0

I want to debug a program but i don't want GDB to print the code it visits out of my local source file scope. The options step(goes into every call) and next(skips stepping into the functions even in the same source file) aren't useful in this case.

Any points on the same?

Thanks

2 Answers 2

1

You can see my answer to Does GDB have a “step-to-next-call” instruction? : there is no native GDB command for that (as far as I know, they may have worked on that), but it's easy to do in Python:

import gdb

class StepNoLibrary (gdb.Command):
    def __init__ (self):
        super (StepNoLibrary, self).__init__ ("step-no-library",
                                              gdb.COMMAND_OBSCURE)

    def invoke (self, arg, from_tty):
        step_msg = gdb.execute("step", to_string=True)

        fname = gdb.newest_frame().function().symtab.objfile.filename

        if fname.startswith("/usr"):
            # inside a library
            SILENT=False
            gdb.execute("finish", to_string=SILENT)
        else:
            # inside the application
            print(step_msg[:-1])

    StepNoLibrary()

just put that in a file, source it with GDB (or in your .gdbinit) and that will provide you the new command step-no-library.

It's easy to read what it does, it goes one step forward, and if the step ends up in a file stored in /usr/*, it finishes it to come back to the application.

Of course that's a naive implementation, if you requirements are different from that just edit the function code!

0

Maybe try using DDD(Data display debugger). Reminds alot about gdb

type in:

ddd --gdb

Then

g++ -O0 -g -o main main.cpp

Hope it might help

Your Answer

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