public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug exp/28428] New: Global variable is always null
@ 2021-10-06 15:09 peter.weber at flapflap dot eu
2021-10-18 17:39 ` [Bug exp/28428] " peter.weber at flapflap dot eu
0 siblings, 1 reply; 2+ messages in thread
From: peter.weber at flapflap dot eu @ 2021-10-06 15:09 UTC (permalink / raw)
To: gdb-prs
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-10-18 17:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-06 15:09 [Bug exp/28428] New: Global variable is always null peter.weber at flapflap dot eu
2021-10-18 17:39 ` [Bug exp/28428] " peter.weber at flapflap dot eu
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).