You can run gdb with --args parameter:

gdb --args executablename arg1 arg2 arg3

If you are doing this often (e.g. when running GDB from a script), you might want to consider the following arguments to automate things further. First, you can place your GDB commands (such as 'run') in a text file and provide the filename to the -x argument. Second, you can have GDB exit after running your commands by providing the --batch argument. A full example:

gdb -x commands.txt --batch --args executablename arg1 arg2 arg3
Answer from Hugo Ideler on Stack Overflow
🌐
University of Michigan
web.eecs.umich.edu › ~sugih › pointers › summary.html
GDB Tutorial
Gdb is a debugger for C (and C++). It allows you to do things like run the program up to a certain point then stop and print out the values of certain variables at that point, or step through the program one line at a time and print out the values of each variable after executing each line.
🌐
GNU Project
sourceware.org › gdb › current › onlinedocs › gdb.html › Starting.html
Starting (Debugging with GDB)
You must first specify the program name with an argument to GDB (see Getting In and Out of GDB), or by using the file or exec-file command (see Commands to Specify Files). If you are running your program in an execution environment that supports processes, run creates an inferior process and makes that process run your program.
🌐
Baylor
cs.baylor.edu › ~donahoo › tools › gdb › tutorial.html
How to Debug Using GDB
Compile the program and execute the program. % g++ -g broken.cpp -o broken % ./broken Whatever the input, the output will be inf. The -g option is important because it enables meaningful GDB debugging. ... Now, we start to run the program in the debugger.
🌐
GNU
ftp.gnu.org › old-gnu › Manuals › gdb › html_chapter › gdb_5.html
Debugging with GDB - Running Programs Under GDB
You must first specify the program name (except on VxWorks) with an argument to GDB (see section Getting In and Out of GDB), or by using the file or exec-file command (see section Commands to specify files). If you are running your program in an execution environment that supports processes, run creates an inferior process and makes that process run your program.
🌐
MIT
web.mit.edu › gnu › doc › html › gdb_6.html
Debugging with GDB - Running Programs Under GDB
You must first specify the program name (except on VxWorks) with an argument to GDB (see section Getting In and Out of GDB), or by using the file or exec-file command (see section Commands to specify files). If you are running your program in an execution environment that supports processes, run creates an inferior process and makes that process run your program.
🌐
VisualGDB
visualgdb.com › gdbreference › commands › run
GDB Command Reference - run command
(gdb) run "Hello World" Starting program: /home/testuser/0.elf "Hello World" Breakpoint 1, main (argc=2, argv=0xbffff774) at 0.cpp:3 3 { (gdb) print *argv@argc $1 = {0xbffff894 "/home/testuser/0.elf", 0xbffff8a9 "Hello World"}
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › c language › gdb-step-by-step-introduction
GDB (Step by Step Introduction) - GeeksforGeeks
January 10, 2025 - Run the code by typing "run or r".If you haven't set any breakpoints, the run command will simply execute the full program. ... To see the value of variable, type "print variable_name or p variable_name".
🌐
University of Michigan
web.eecs.umich.edu › ~sugih › pointers › gdbQS.html
gdb QuickStart
Start gdb. Type "gdb [filename]" where [filename] is the name of the compiled file you wish to debug (the name you type to run your program).
🌐
Qnx
qnx.com › developers › docs › qnxcar2 › topic › com.qnx.doc.neutrino.prog › topic › using_gdb_RunningPrograms.html
Running programs under GDB
To run a program under GDB, you must first generate debugging information when you compile it. You may start GDB with its arguments, if any, in an environment of your choice. You may redirect your program's input and output, debug an already running process, or kill the process being debugged.
🌐
The Ohio State University
u.osu.edu › cstutorials › 2018 › 09 › 28 › how-to-debug-c-program-using-gdb-in-6-simple-steps
How to Debug C Program using gdb in 6 Simple Steps
While executing the program, the ... 10 Breakpoint 1 at 0x804846f: file factorial.c, line 10. ... You can start running the program using the run command in the gdb debugger....
🌐
Linux Man Pages
man7.org › linux › man-pages › man1 › gdb.1.html
gdb(1) - Linux manual page
You can use GDB to debug programs written in C, C++, Fortran and Modula-2. GDB is invoked with the shell command "gdb". Once started, it reads commands from the terminal until you tell it to exit with the GDB command "quit" or "exit". You can get online help from GDB itself by using the command ...
🌐
Apple Developer
developer.apple.com › library › archive › documentation › DeveloperTools › gdb › gdb › gdb_3.html
Debugging with gdb - Getting In and Out of gdb
This will cause gdb to debug gcc, and to set gcc's command-line arguments (see section Your program's arguments) to `-O2 -c foo.c'. You can run gdb without printing the front material, which describes GDB's non-warranty, by specifying -silent:
🌐
Apple Developer
developer.apple.com › library › archive › documentation › DeveloperTools › gdb › gdb › gdb_5.html
Debugging with gdb - Running Programs Under gdb
You must first specify the program name (except on VxWorks) with an argument to GDB (see section Getting In and Out of GDB), or by using the file or exec-file command (see section Commands to specify files). If you are running your program in an execution environment that supports processes, run creates an inferior process and makes that process run your program.
🌐
University of Toronto
cs.toronto.edu › ~krueger › csc209h › tut › gdb_tutorial.html
gdb tutorial
(gdb) condition 1 num==50 (gdb) run Starting program: /student/nguyen_h/csc408/contribuition/crash enter a number: 50 Breakpoint 1, sum_to_n (num=50) at crash.c:10 10 for(i=1;i<=num;i++) (gdb) n 11 sum+=i; (gdb) n 10 for(i=1;i<=num;i++) (gdb) u 12 return sum; (gdb)
🌐
GNU Project
sourceware.org › gdb › current › onlinedocs › gdb.html › gdb-man.html
gdb man (Debugging with GDB)
You can use GDB to debug programs written in C, C++, Fortran and Modula-2. GDB is invoked with the shell command gdb. Once started, it reads commands from the terminal until you tell it to exit with the GDB command quit or exit. You can get online help from GDB itself by using the command help.
🌐
University of Rochester
cs.rochester.edu › u › nelson › courses › csc_173 › review › gdb.html
Debugging Programs with GDB
Kill it? (y or n) y Load new symbol table from "gdbprog"? (y or n) y Reading symbols from gdbprog... done. (gdb) run Starting program: gdbprog