public inbox for gdb-prs@sourceware.org help / color / mirror / Atom feed
From: "peter.weber at flapflap dot eu" <sourceware-bugzilla@sourceware.org> To: gdb-prs@sourceware.org Subject: [Bug exp/28428] New: Global variable is always null Date: Wed, 06 Oct 2021 15:09:58 +0000 [thread overview] Message-ID: <bug-28428-4717@http.sourceware.org/bugzilla/> (raw) https://sourceware.org/bugzilla/show_bug.cgi?id=28428 Bug ID: 28428 Summary: Global variable is always null Product: gdb Version: 11.1 Status: UNCONFIRMED Severity: normal Priority: P2 Component: exp Assignee: unassigned at sourceware dot org Reporter: peter.weber at flapflap dot eu Target Milestone: --- Created attachment 13709 --> https://sourceware.org/bugzilla/attachment.cgi?id=13709&action=edit optarg Hello! I'm using GNU getopt[1] and during debugging the global variable 'char * optarg' always prints 0x00 i.e. nullptr. While the variable actually contains a valid pointer address as a value. Upon assignment, the correct value is therefore used and the program executes well in defined behavior. My expectation is, that GDB shows the same value as is used by the actual program in execution. I'm using Archlinux with GCC 11.1 and GDB 11.1. The attachment contains a sample code. Steps to reproduce: -------------------------------------------------------------------------------- $ gcc -o getopt getopt.c -g # debugging ON, optimizations OFF $ gdb getopt (gdb) b 26 # set breakpoint (gdb) r -cfoo (gdb) p optarg $1 = 0x0 # no "foo"? (gdb) n # executes cvalue = optarg (gdb) p cvalue $2 = 0x7fffffffea99 "foo" # here it is, please don't expect to get the same memory-address -------------------------------------------------------------------------------- When I stop the execution on line 26 and print 'optarg' I receive 0x00. When I step further to line 28 and print 'cvalue' it contains the passed command line parameter value. The 'optarg' still shows 0x00 as a value. I figured out that a syntax which is used to refer to hidden variables or similar[3] can be used as a workaround: p (char*)'optarg@GLIBC_2.2.5' I figured that out during reading other C++-related questions and playing with tab completion in GDB. For further info, you can read the corresponding question at Stackoverflow[2]. Do I make something wrong? Is this a bug? Thank you Peter [1] https://www.gnu.org/software/libc/manual/html_node/Using-Getopt.html [2] https://stackoverflow.com/q/69409047/1054324 [3] https://sourceware.org/gdb/current/onlinedocs/gdb/Variables.html -- You are receiving this mail because: You are on the CC list for the bug.
next reply other threads:[~2021-10-06 15:09 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-10-06 15:09 peter.weber at flapflap dot eu [this message] 2021-10-18 17:39 ` [Bug exp/28428] " peter.weber at flapflap dot eu
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-28428-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: linkBe 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).