public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "m.weghorn at posteo dot de" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug server/25893] New: gdbserver incorrectly handles program args containing space
Date: Wed, 29 Apr 2020 09:14:49 +0000	[thread overview]
Message-ID: <bug-25893-4717@http.sourceware.org/bugzilla/> (raw)

https://sourceware.org/bugzilla/show_bug.cgi?id=25893

            Bug ID: 25893
           Summary: gdbserver incorrectly handles program args containing
                    space
           Product: gdb
           Version: HEAD
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: server
          Assignee: unassigned at sourceware dot org
          Reporter: m.weghorn at posteo dot de
  Target Milestone: ---

gdbserver cannot handle program arguments containing space, but splits such
arguments into separate ones.

# Steps to reproduce:

1) compile small sample program ("test.cxx") given below:
   g++ -g -O0 -o  test test.cxx

2) run with gdbserver, passing an arg containing space
  gdbserver localhost:50505 test "hello world"

3) attach with GDB, and inspect the program arguments:

(gdb) target remote localhost:50505
[...]
(gdb) break main
Breakpoint 1 at 0x555555555174: file test.cxx, line 3.
(gdb) c
Continuing.
[...]
Breakpoint 1, main (argc=3, argv=0x7fffffffddf8) at test.cxx:3
3           std::cout << argv[1] << std::endl;
(gdb) p argc
$1 = 3
(gdb) p argv[1]
$2 = 0x7fffffffe1a6 "hello"
(gdb) p argv[2]
$3 = 0x7fffffffe1ac "world"
(gdb) 


# Actual result:

Instead of showing a single argument "hello world", two separate arguments
("hello", "world") are shown.

# Expected result:

A single argument "hello world" should have been passed to the program, as is
the case when using "plain" gdb instead of gdbserver:

$ gdb --args test "hello world"
[...]
(gdb) break main
Breakpoint 1 at 0x1174: file test.cxx, line 3.
(gdb) r
Starting program: /home/michi/temp/2020-04-24_gdb_gdbserver_args/test hello\
world

Breakpoint 1, main (argc=2, argv=0x7fffffffddd8) at test.cxx:3
3           std::cout << argv[1] << std::endl;
(gdb) p argc
$1 = 2
(gdb) p argv[1]
$2 = 0x7fffffffe197 "hello world"


# Further notes

I initially experienced this bug with gdb version 9.1 in Debian testing
(amd64), but it's also reproducible with current git master, as of commit
0b2f8a3bbb595a99dd7977caa6382aab25630115.

I plan to submit patches that show a potential approach to fix this.

# Sample program "test.cxx":

  #include <iostream>
  int main(int argc, char** argv) {
      std::cout << argv[1] << std::endl;
      return 0;
  }

-- 
You are receiving this mail because:
You are on the CC list for the bug.

             reply	other threads:[~2020-04-29  9:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-29  9:14 m.weghorn at posteo dot de [this message]
2020-04-29  9:15 ` [Bug server/25893] " m.weghorn at posteo dot de
2020-04-29 11:23 ` m.weghorn at posteo dot de
2020-05-25 15:42 ` cvs-commit at gcc dot gnu.org
2020-05-25 15:43 ` simark at simark dot ca
2020-07-16 19:48 ` tromey at sourceware dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-25893-4717@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).