public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug python/20077] gdb.Value string object has strlen of 1 after backtrace
       [not found] <bug-20077-4717@http.sourceware.org/bugzilla/>
@ 2023-11-24 13:29 ` ssbssa at sourceware dot org
  0 siblings, 0 replies; only message in thread
From: ssbssa at sourceware dot org @ 2023-11-24 13:29 UTC (permalink / raw)
  To: gdb-prs

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

Hannes Domani <ssbssa at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ssbssa at sourceware dot org

--- Comment #8 from Hannes Domani <ssbssa at sourceware dot org> ---
There are 2 different declarations of the linux_banner variable:

https://github.com/torvalds/linux/blob/master/init/version.c#L50:

const char linux_banner[] __weak;

https://github.com/torvalds/linux/blob/master/init/version-timestamp.c#L28-L30:

const char linux_banner[] =
        "Linux version " UTS_RELEASE " (" LINUX_COMPILE_BY "@"
        LINUX_COMPILE_HOST ") (" LINUX_COMPILER ") " UTS_VERSION "\n";


We can try this ourselves with this reproducer:

main.c:
```

int part1();
int part2();

int main()
{
  int sum = part1();
  sum += part2();
  return sum;
}
```

part1.c:
```

const char linux_banner[] __attribute__((weak));

int part1()
{
  return 1;
}
```

part2.c:
```

const char linux_banner[] = "Linux version 1.2.3.4";

int part2()
{
  return 2;
}
```

$ gcc -g -o example main.c part1.c part2.c


Depending on the declaration that was last 'used', this gives different
results.

With a breakpoint in part1.c with the weak declaration:
```
$ gdb -q example.exe
Reading symbols from example.exe...
(gdb) b part1
Breakpoint 1 at 0x140001634: file part1.c, line 6, column 10.
(gdb) b 9
Breakpoint 2 at 0x14000161d: file main.c, line 9, column 10.
(gdb) r
Starting program: C:\src\tests\example.exe

Breakpoint 1, part1 () at part1.c:6
6         return 1;
                 ^
(gdb) c
Continuing.

Breakpoint 2, main () at main.c:9
9         return sum;
                 ^
(gdb) py print(repr(gdb.parse_and_eval("linux_banner").string()))
''
(gdb) pt linux_banner
type = const char []
```


With a breakpoint in part2.c with the full declaration:
```
$ gdb -q example.exe
Reading symbols from example.exe...
(gdb) b part2
Breakpoint 1 at 0x140001644: file part2.c, line 6, column 10.
(gdb) b 9
Breakpoint 2 at 0x14000161d: file main.c, line 9, column 10.
(gdb) r
Starting program: C:\src\tests\example.exe

Breakpoint 1, part2 () at part2.c:6
6         return 2;
                 ^
(gdb) c
Continuing.

Breakpoint 2, main () at main.c:9
9         return sum;
                 ^
(gdb) py print(repr(gdb.parse_and_eval("linux_banner").string()))
'Linux version 1.2.3.4'
(gdb) pt linux_banner
type = const char [22]
```

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-11-24 13:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-20077-4717@http.sourceware.org/bugzilla/>
2023-11-24 13:29 ` [Bug python/20077] gdb.Value string object has strlen of 1 after backtrace ssbssa at sourceware dot org

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).