This question already has answers here:
How to load program reading stdin and taking parameters in gdb?
(6 answers)
How do I pass a command line argument while starting up GDB in Linux? [duplicate]
(4 answers)
Closed 9 years ago.
often i see some gdb guide using examples without parameters. But in parctice, i need to gdb debug a programe with parameters.
this program is run as "./voronoi -t outputfile", -t is programme voronoi itself parameter, is input, and outputfile is outputfile. but when i using "gdb ./voronoi -t outputfile", it will tell me some error, but when using no gdb debug, run "./voronoi -t outputfile" is OK.
How make it both can gdb debugging and aslo with parameters? How to set the parameters?
You may want to take a look at the run and start commands of gdb—you can pass them the commandline parameters just like you are used to at the shell prompt:
% gdb my_program
[...]
start par1 par2 par3 ...
$ gdb program
break linenumber|functionName
run [parameters]
if your system is windows,you can do this:
1.gdb your_program
2.set args para1 para2 para3...
Related
This question already has answers here:
How do I run a program with commandline arguments using GDB within a Bash script?
(9 answers)
Closed 2 years ago.
I have to debug a program that has errors in it as part of my assignment. However, I must first pass command line arguments in order to solve this problem.
I do:
gdb -tui InsertionSortWithErrors
which works, but after that I don't know how to pass arguments. I used gdb -help and it says something about --args which I also tried and it didn't work.
I want to be able to get the debugger+the GUIand pass command line arguments.
Once gdb starts, you can run the program using "r args".
So if you are running your code by:
$ executablefile arg1 arg2 arg3
Debug it on gdb by:
$ gdb executablefile
(gdb) r arg1 arg2 arg3
Try
gdb --args InsertionSortWithErrors arg1toinsort arg2toinsort
Another option, once inside the GDB shell, before running the program, you can do
(gdb) set args file1 file2
and inspect it with:
(gdb) show args
I'm using GDB7.1.1, as --help shows:
gdb [options] --args executable-file [inferior-arguments ...]
IMHO, the order is a bit unintuitive at first.
This question already has answers here:
How do you get assembler output from C/C++ source in GCC?
(17 answers)
How to remove "noise" from GCC/clang assembly output?
(3 answers)
Closed 4 years ago.
I'm trying learning assembly language and i need to know how to read the assembly varsion of a c program from the windows 10 command prompt.
I've tried using C:\users\prete\Desktop\booksrc$ gcc -g firstprog.c but it doesn't work
please help me
thank you!
I am not sure about windows, but as far as I know, the assembly output is gained by the -S option for gcc.
Try gcc -S firstprog.c
The output will be firstprog.s in AT&T syntax. If you want it in the intel syntax (might be rather helpful if you use NASM/MASM/YASM and such for assembling), try:
gcc -S -masm=intel firstprog.c
This question already has answers here:
Preprocessor output
(6 answers)
Closed 5 years ago.
I came across this option of -E while navigating and searching for where the file descriptors of stdio.h is stored in the machine? But I am not sure what exactly this command gcc -E do? Can it be used to view the file descriptor of the stdio.h fie stored in /usr/include/ directory?
It tells GCC to stop after the preprocessing stage. Details in the link.
https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html#Overall-Options
It will show the output the compiler produces after expanding all macros.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I wrote a shell in C. There are some problems while running some programs on it.How can I run a program on a shell while debugging the shell in the gdb?
First use -g option to compile with debugging flags, for use with gdb.
Then run.
gdb shellapp
...
run someapps
...
For a quick reading How to Debug C Program using gdb in 6 Simple Steps and GDB Tutorial
Or do you mean run a program in the background?
You can attach by gdb to already running shell process from another console. This way your shell output will not interfere with gdb output and you can run programs in shell as usual.
Run your implementation of shell in 1st console window
Open 2nd console and find pid number of already running shell using ps command
Start gdb in 2nd console and attach to shell using it's pid number like this:
:~$ gdb -q
(gdb) attach 3479
Attaching to process 3479
Now you can set breakpoints and continue shell execution:
(gdb) b SomeFunction
(gdb) c
Continuing.
From this point you have 2 consoles:
the one where your shell is running
and the second where gdb runs attached to shell
You can use shell as usual: run other programs on it or do whatever else. And at the same time you can observe shell execution in 2nd console inside gdb. The point is that output of these 2 processes are separated from each other which would be impossible if you run shell directly inside gdb in just one console.
This question already has answers here:
How do I run a program with commandline arguments using GDB within a Bash script?
(9 answers)
Closed 2 years ago.
I have to debug a program that has errors in it as part of my assignment. However, I must first pass command line arguments in order to solve this problem.
I do:
gdb -tui InsertionSortWithErrors
which works, but after that I don't know how to pass arguments. I used gdb -help and it says something about --args which I also tried and it didn't work.
I want to be able to get the debugger+the GUIand pass command line arguments.
Once gdb starts, you can run the program using "r args".
So if you are running your code by:
$ executablefile arg1 arg2 arg3
Debug it on gdb by:
$ gdb executablefile
(gdb) r arg1 arg2 arg3
Try
gdb --args InsertionSortWithErrors arg1toinsort arg2toinsort
Another option, once inside the GDB shell, before running the program, you can do
(gdb) set args file1 file2
and inspect it with:
(gdb) show args
I'm using GDB7.1.1, as --help shows:
gdb [options] --args executable-file [inferior-arguments ...]
IMHO, the order is a bit unintuitive at first.