Re: [PATCH] gdb/gdbserver: pass inferior arguments as a single string

Andrew Burgess
2025-09-16T14:55:39Z

Luis <luis.machado.foss@gmail.com> writes:

> I think I'm running into a change in behavior for --args, where it now says
> no program was specified when previously it was ok.
>
> Just a standard....
>
> ./gdb/gdb -ex run --args gdb/gdb gdb/gdb -ex start

And to debug it, I did:

gdb --args ./gdb/gdb -ex run --args gdb/gdb gdb/gdb -ex start

It's GDB all the way down!

Anyway.

The patch below fixes this problem. I still need to write a test for
this and write a commit message. I'll try to do that later today, or it
might have to be first thing tomorrow.

Good news is this bug is not in GDB 17 branch.

Thanks,
Andrew

---

diff --git i/gdb/main.c w/gdb/main.c
index 04c33638bec..f3049600a06 100644
--- i/gdb/main.c
+++ w/gdb/main.c
@@ -866,9 +866,14 @@ captured_main_1 (struct captured_main_args *context)
{
int option_index;

+ /* If the previous argument was --args or --no-escape-args, then
+ stop argument processing. */
+ if (set_args != NO_ARGS)
+ break;
+
c = getopt_long_only (argc, argv, "",
long_options, &option_index);
- if (c == EOF || set_args != NO_ARGS)
+ if (c == EOF)
break;

/* Long option that takes an argument. */