-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace BFD -> libelf, merge MMap class and ProcessInfo, split
function and instruction resolution. -> split function resolution and instruction resolution -> integrate mmap code into ProcessInfo The mmap code is not used outside of ProcessInfo and every function in ProcessInfo was already a paper thin wrapper around something in Mmap -> replace binutils/libbfd with elfutils/libdw/libelf - API usable by human beings - Actual documentation - Has support for DWARF
- Loading branch information
Showing
12 changed files
with
717 additions
and
494 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#pragma once | ||
|
||
#include <lo2s/address.hpp> | ||
#include <lo2s/function_resolver.hpp> | ||
#include <lo2s/line_info.hpp> | ||
|
||
#include <map> | ||
extern "C" | ||
{ | ||
#include <elfutils/libdw.h> | ||
#include <elfutils/libdwfl.h> | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
} | ||
|
||
namespace lo2s | ||
{ | ||
class DwarfFunctionResolver : public FunctionResolver | ||
{ | ||
public: | ||
DwarfFunctionResolver(std::string name); | ||
|
||
static FunctionResolver& cache(std::string name) | ||
{ | ||
return StringCache<DwarfFunctionResolver>::instance()[name]; | ||
} | ||
|
||
~DwarfFunctionResolver(); | ||
virtual LineInfo lookup_line_info(Address addr) override; | ||
|
||
std::string name() | ||
{ | ||
return name_; | ||
} | ||
|
||
private: | ||
std::map<Range, LineInfo> cache_; | ||
Dwfl_Callbacks cb; | ||
Dwfl* dwfl_ = nullptr; | ||
Dwfl_Module* mod_ = nullptr; | ||
std::string name_; | ||
}; | ||
} // namespace lo2s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* This file is part of the lo2s software. | ||
* Linux OTF2 sampling | ||
* | ||
* Copyright (c) 2024, | ||
* Technische Universitaet Dresden, Germany | ||
* | ||
* lo2s is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* lo2s is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with lo2s. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <lo2s/line_info.hpp> | ||
#include <lo2s/util.hpp> | ||
|
||
#include <string> | ||
#include <regex> | ||
|
||
namespace lo2s | ||
{ | ||
class FunctionResolver | ||
{ | ||
public: | ||
FunctionResolver(const std::string& name) : name_(name) | ||
{ | ||
} | ||
|
||
static FunctionResolver& cache(const std::string& name) | ||
{ | ||
return StringCache<FunctionResolver>::instance()[name]; | ||
} | ||
|
||
virtual LineInfo lookup_line_info(Address) | ||
{ | ||
return LineInfo::for_binary(name_); | ||
} | ||
|
||
std::string name() | ||
{ | ||
return name_; | ||
} | ||
|
||
protected: | ||
std::string name_; | ||
}; | ||
|
||
class Kallsyms : public FunctionResolver | ||
{ | ||
public: | ||
Kallsyms() : FunctionResolver("[kernel]") | ||
{ | ||
std::map<Address, std::string> entries; | ||
std::ifstream ksyms_file("/proc/kallsyms"); | ||
|
||
std::regex ksym_regex("([0-9a-f]+) (?:t|T) ([^[:space:]]+)"); | ||
std::smatch ksym_match; | ||
|
||
std::string line; | ||
|
||
// Emplacing into entries map takes care of sorting symbols by address | ||
while (getline(ksyms_file, line)) | ||
{ | ||
if (std::regex_match(line, ksym_match, ksym_regex)) | ||
{ | ||
std::string sym_str = ksym_match[2]; | ||
uint64_t sym_addr = stoull(ksym_match[1], nullptr, 16); | ||
entries.emplace(std::piecewise_construct, std::forward_as_tuple(sym_addr), | ||
std::forward_as_tuple(sym_str)); | ||
} | ||
} | ||
|
||
std::string sym_str = ""; | ||
Address prev = 0; | ||
|
||
for (auto& entry : entries) | ||
{ | ||
if (prev != 0 && prev != entry.first) | ||
{ | ||
kallsyms_.emplace(std::piecewise_construct, | ||
std::forward_as_tuple(prev, entry.first), | ||
std::forward_as_tuple(sym_str)); | ||
} | ||
else | ||
{ | ||
start_ = entry.first.value(); | ||
} | ||
sym_str = entry.second; | ||
prev = entry.first; | ||
} | ||
|
||
if (sym_str != "") | ||
{ | ||
kallsyms_.emplace(std::piecewise_construct, | ||
std::forward_as_tuple(prev, Address((uint64_t)-1)), | ||
std::forward_as_tuple(sym_str)); | ||
} | ||
} | ||
|
||
static Kallsyms& cache() | ||
{ | ||
static Kallsyms k; | ||
return k; | ||
} | ||
|
||
uint64_t start() | ||
{ | ||
return start_; | ||
} | ||
|
||
virtual LineInfo lookup_line_info(Address addr) override | ||
{ | ||
return LineInfo::for_function("[kernel]", kallsyms_.at(addr + start_).c_str(), 1, ""); | ||
} | ||
|
||
private: | ||
std::map<Range, std::string> kallsyms_; | ||
uint64_t start_; | ||
}; | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* This file is part of the lo2s software. | ||
* Linux OTF2 sampling | ||
* | ||
* Copyright (c) 2024, | ||
* Technische Universitaet Dresden, Germany | ||
* | ||
* lo2s is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* lo2s is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with lo2s. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <lo2s/address.hpp> | ||
#ifdef HAVE_RADARE | ||
#include <lo2s/radare.hpp> | ||
#endif | ||
#include <lo2s/util.hpp> | ||
|
||
#include <string> | ||
namespace lo2s | ||
{ | ||
class InstructionResolver | ||
{ | ||
public: | ||
InstructionResolver() | ||
{ | ||
} | ||
|
||
static InstructionResolver& cache() | ||
{ | ||
static InstructionResolver ir; | ||
return ir; | ||
} | ||
|
||
virtual std::string lookup_instruction(Address) | ||
{ | ||
return ""; | ||
} | ||
}; | ||
#ifdef HAVE_RADARE | ||
class RadareInstructionResolver : public InstructionResolver | ||
{ | ||
public: | ||
RadareInstructionResolver(std::string name) : radare_(name) | ||
{ | ||
} | ||
|
||
static RadareInstructionResolver& cache(const std::string& name) | ||
{ | ||
return StringCache<RadareInstructionResolver>::instance()[name]; | ||
} | ||
|
||
virtual std::string lookup_instruction(Address ip) | ||
{ | ||
return radare_.instruction(ip); | ||
} | ||
|
||
RadareResolver radare_; | ||
}; | ||
#endif // HAVE_RADARE | ||
} // namespace lo2s |
Oops, something went wrong.