<commit_before>// Copyright (c) 2022 The Orbit Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ClientData/FunctionInfo.h"

#include <absl/strings/match.h>
#include <absl/strings/str_join.h>
#include <xxhash.h>

#include "ClientData/ModuleData.h"
#include "ClientData/ProcessData.h"
#include "ModuleUtils/VirtualAndAbsoluteAddresses.h"

namespace orbit_client_data {

uint64_t FunctionInfo::GetPrettyNameHash() const {
  return XXH64(pretty_name_.data(), pretty_name_.size(), 0xBADDCAFEDEAD10CC);
}

uint64_t FunctionInfo::ComputeFileOffset(const ModuleData& module) const {
  return module.ConvertFromVirtualAddressToOffsetInFile(address());
}

std::optional<uint64_t> FunctionInfo::GetAbsoluteAddress(const ProcessData& process,
                                                         const ModuleData& module) const {
  std::vector<uint64_t> page_aligned_base_addresses =
      process.GetModuleBaseAddresses(module.file_path(), module.build_id());

  if (page_aligned_base_addresses.empty()) {
    return std::nullopt;
  }

  if (page_aligned_base_addresses.size() > 1) {
    ORBIT_ERROR(
        "Found multiple mappings for \"%s\" with build_id=%s [%s]: "
        "will use the first one as a base address",
        module.file_path(), module.build_id(),
        absl::StrJoin(page_aligned_base_addresses, ",", [](std::string* out, uint64_t address) {
          return out->append(absl::StrFormat("%#x", address));
        }));
  }

  ORBIT_CHECK(!page_aligned_base_addresses.empty());

  return orbit_module_utils::SymbolVirtualAddressToAbsoluteAddress(
      address(), page_aligned_base_addresses.at(0), module.load_bias(),
      module.executable_segment_offset());
}

bool FunctionInfo::IsFunctionSelectable() const {
  constexpr const char* kLibOrbitUserSpaceInstrumentation = "liborbituserspaceinstrumentation.so";
  return module_path().find(kLibOrbitUserSpaceInstrumentation) == std::string::npos;
}

}  // namespace orbit_client_data<commit_msg>Make wine_syscall_dispatcher not selectable. (#4125)<commit_after>// Copyright (c) 2022 The Orbit Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ClientData/FunctionInfo.h"

#include <absl/strings/match.h>
#include <absl/strings/str_join.h>
#include <xxhash.h>

#include "ClientData/ModuleData.h"
#include "ClientData/ProcessData.h"
#include "ModuleUtils/VirtualAndAbsoluteAddresses.h"

namespace orbit_client_data {

uint64_t FunctionInfo::GetPrettyNameHash() const {
  return XXH64(pretty_name_.data(), pretty_name_.size(), 0xBADDCAFEDEAD10CC);
}

uint64_t FunctionInfo::ComputeFileOffset(const ModuleData& module) const {
  return module.ConvertFromVirtualAddressToOffsetInFile(address());
}

std::optional<uint64_t> FunctionInfo::GetAbsoluteAddress(const ProcessData& process,
                                                         const ModuleData& module) const {
  std::vector<uint64_t> page_aligned_base_addresses =
      process.GetModuleBaseAddresses(module.file_path(), module.build_id());

  if (page_aligned_base_addresses.empty()) {
    return std::nullopt;
  }

  if (page_aligned_base_addresses.size() > 1) {
    ORBIT_ERROR(
        "Found multiple mappings for \"%s\" with build_id=%s [%s]: "
        "will use the first one as a base address",
        module.file_path(), module.build_id(),
        absl::StrJoin(page_aligned_base_addresses, ",", [](std::string* out, uint64_t address) {
          return out->append(absl::StrFormat("%#x", address));
        }));
  }

  ORBIT_CHECK(!page_aligned_base_addresses.empty());

  return orbit_module_utils::SymbolVirtualAddressToAbsoluteAddress(
      address(), page_aligned_base_addresses.at(0), module.load_bias(),
      module.executable_segment_offset());
}

bool FunctionInfo::IsFunctionSelectable() const {
  constexpr const char* kLibOrbitUserSpaceInstrumentation = "liborbituserspaceinstrumentation.so";
  if (absl::StrContains(module_path(), kLibOrbitUserSpaceInstrumentation)) {
    return false;
  }

  constexpr const char* kNameOfWineSyscallDispatcher = "__wine_syscall_dispatcher";
  constexpr const char* kNameOfWineSyscallDispatcherModule = "ntdll.so";
  if (absl::StrContains(pretty_name(), kNameOfWineSyscallDispatcher) &&
      absl::StrContains(module_path(), kNameOfWineSyscallDispatcherModule)) {
    return false;
  }

  return true;
}

}  // namespace orbit_client_data
{'fraction_non_alphanumeric': 0.11539313399778516, 'fraction_numerical': 0.010188261351052049, 'mean_word_length': 4.709228824273072, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2623775', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1373, 'n_words': 276}