1

Currently GDB prints only trivial arguments in backtrace (only scalars); something like below

(gdb) bt 1
(gdb) function1(this=this@entry=0xfff6c20, x1=-1, x2=3, x3=...

and so on. x3 here could be a array/STL vector and by default GDB does not display it.

I am using lot of STL vectors and Blitz arrays in my code.

I have routines in .gdbinit file to display STL vectors, and subroutines in c++ where I can make use of call functionality in GDB, which can display the array contents. To manually print the vector/array contents, I would use

(gdb) printVector vector_name -> this is a routine in my .gdbinit
(gdb) call printBlitzArray(array_name) -> this is a routine inside my executable itself.

How can we make GDB display the non trivial arguments of a function like below.

void myFunc(int x1, int x2, std::vector<int> x3, blitz::Array<bool, 1> x4)

I got to know using set print frame-arguments all can display some of the non trivial arguments. But how to really print arguments where GDB may not have a native support for printing them. The intent is to automatically print all the arguments at the start of the function (atleast whichever we can).

I can write a GDB script and add prints individually for each vector/array, but doing this for every function would be very time consuming, since I have a large number of functions. This would help a lot to accelerate my debug.

Any suggestion is highly appreciated.

Thanks a lot in advance !

3
  • what flags are you compiling with? are you compiling with -rdynamic? Commented May 11, 2020 at 10:28
  • Hi,I am not using -rdynamic. Could you suggest if it can be used for printing non native/STL/Blitz data types while running bactrace in GDB ? if so how ? Thanks a lot ! Commented May 11, 2020 at 11:28
  • as much as I know, building with -rdynamic would copy all regular symbols into dynamic-symbol section of your executable hence considering you are compiling a C++ piece of code and name mangling is used, it could provide extra information to GDB during runtime about your backtraced symbols, I once implemented backtracing and -rdynamic was what fixed my problem Commented May 11, 2020 at 11:29

1 Answer 1

-1

I've just tested this on my own machine, use -rdynamic when compiling. -rdynamic flag basically makes an additional copy for all of your symbols (not just dynamic symbols or externally dependant) to the dynamic symbol table of your executable, thus allowing them to be loaded into your memory during runtime of the program and not simply used by your linker as some metadata, this provides any backtracing mechanism the fully name-mangled symbol and allowing it to be parsed into your original function (without the actual names of function parameters, just types), hope this helps! :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.