I have c++ program which I run by passing string with it.
g++ -o a main.cpp -lpthread
and execute it with ./a "Good nice"
But how I debug it with gdb? main.cpp calling functions from other files which are included in it.
gdb ./a "Good nice"
takes "--" as files and says no such file!
I want to debug line by line!
Compile the C program with debugging option -g Compile your C program with -g option. This allows the compiler to collect the debugging information. Note: The above command creates a.out file which will be used for debugging as shown below. Step 2. Launch gdb Launch the C debugger (gdb) as shown below. Step 3. Set up a break point inside C program
You can pass arguments if the program needs some command-line arguments to be passed to it: $ (gdb) run arg1 arg2 Debugging with GDB lets you investigate the core file as well. The core file contains information about when a program crashed.
GNU or GDB debugger is an application for finding out how your C or C++ program runs or for analyzing the moment the program crashes. You can perform many useful tasks with GDB: run the program, stop the program under specific conditions, analyze the situation, make modifications, and test new changes.
Step 1. Compile the C program with debugging option -g Compile your C program with -g option. This allows the compiler to collect the debugging information. Note: The above command creates a.out file which will be used for debugging as shown below. Step 2.
Use the --args
option of gdb:
gdb --args ./a "Good nice"
Also add the -g
option to your compiler call, because otherwise gdb won't be able to connect your executable with your source code:
g++ -g -o a main.cpp -lpthread
Use gdb without argument
gdb ./a
Then in gdb, before running the program
set args "Good nice"
And you can see what arguments you set, use
show args
See here for detail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With