I have the following C++ code:
main.cpp:
#include "a.h"
int main(){
int x[3];
some_macro(x)
// comment
// comment
return x[2];
}
a.h:
template <typename T>
inline void some_macro_break_point()
{
some_macro_break_point();
}
#define some_macro(name)
{
some_macro_break_point();
}
and using GDB python extension I’m trying to get the line and file where the macro was called while using GDB, given the fact that I have an automatic break point over some_macro_break_point
I do the following when hitting the break point:
frame = gdb.newest_frame()
frame = frame.older()
pc = frame.pc()
symtab_line = gdb.find_pc_line(pc)
print(">>>> ", symtab_line.symtab.fullname() + ":" + str(symtab_line.line), "<<<<n")
but in case I have comments under the macro call in the main, I will get the line + <number_of_comments_under_it>
how I can detect the exact line the macro was called from the main correctly? when I don’t have comments I get the line with offset of 1.
I tried tp get the symtab of the gdb frame but values were affected by the fact that there were comments under the macro call.
Ruba Rushrush is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.