45 static std::string getLine(
const std::string&,
const std::string&);
46 static std::string pipeOpen(
const std::string& cmd,
const int lineNum = 0);
51 int main(
int argc,
char *argv[])
53 int optHelp = 0, optFunctions = 0, optVersion = 0;
55 std::string filename =
"a.out";
56 std::vector<std::string> addresses;
58 static struct option opts[] =
60 {
"target", required_argument,
nullptr,
'b' },
61 {
"demangle", required_argument,
nullptr,
'C' },
62 {
"exe", required_argument,
nullptr,
'e' },
63 {
"functions", no_argument, &optFunctions, 1 },
64 {
"version", no_argument, &optVersion, 1 },
65 {
"basename", no_argument,
nullptr,
's' },
66 {
"inlines", no_argument,
nullptr,
'i' },
67 {
"section", required_argument,
nullptr,
'j' },
68 {
"help", no_argument, &optHelp, 1 },
69 {
nullptr, 0,
nullptr, 0 }
72 while ((ch = getopt_long(argc, argv,
"b:C:e:fVsij:H", opts,
nullptr)) != -1)
77 filename = std::string(optarg);
105 addresses.push_back(std::string(*argv));
110 for (
const auto& addr : addresses)
112 std::cout<<
'\n' << getLine(filename, addr).c_str() <<
'\n';
122 <<
"usage: addr2line [-e filename|--exe=filename]" 130 std::cout<<
"OpenFOAM addr2line emulator\n" <<
std::endl;
137 std::string pipeOpen(
const std::string& cmd,
int lineNum)
141 FILE* handle = popen(cmd.c_str(),
"r");
142 if (!handle)
return str;
152 cnt <= lineNum && (nread = ::getline(&buf, &len, handle)) >= 0;
163 str.resize(str.size()-1);
175 std::string getLine(
const std::string& filename,
const std::string& addr)
180 "echo 'image lookup -va " + addr
183 +
"-O 'target create --no-dependents -a x86_64 " 186 +
"target module load -f " 188 +
" __TEXT 0x0' 2>/dev/null" 189 +
" | grep LineEntry" 196 if (!
re.match(line, groups))
202 line = groups[1].
str() +
":" + groups[2].
str();
errorManipArg< error, int > exit(error &err, const int errNo=1)
const dimensionedScalar re
Classical electron radius: default SI units: [m].
Ostream & endl(Ostream &os)
Add newline and flush stream.
Sub-ranges of a string with a structure similar to std::match_results, but without the underlying reg...
StringType str(size_t pos) const
Retrieve element at pos, converted to a string type.
const std::string version
OpenFOAM version (name or stringified number) as a std::string.
Wrapper around POSIX extended regular expressions with some additional prefix-handling. The prefix-handling is loosely oriented on PCRE regular expressions and provides a simple means of tuning the expressions.