public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug python/31805] New: Division by zero in target_read_string()
@ 2024-05-27 11:47 kkilger at gmail dot com
2024-05-27 16:08 ` [Bug python/31805] " kkilger at gmail dot com
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: kkilger at gmail dot com @ 2024-05-27 11:47 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=31805
Bug ID: 31805
Summary: Division by zero in target_read_string()
Product: gdb
Version: HEAD
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: python
Assignee: unassigned at sourceware dot org
Reporter: kkilger at gmail dot com
Target Milestone: ---
Created attachment 15538
--> https://sourceware.org/bugzilla/attachment.cgi?id=15538&action=edit
Patch which solves the problem
I encountered a division by zero in target_read_string() when using the
python pretty printer on a custom C++ string of type:
using MY_CHAR = wchar_t;
std::string<MY_CHAR, std::char_traits<MY_CHAR>, custom_allocator_type<MY_CHAR>>
I have a fix which solves this problem for me. I mailed the fix also to the
mailing list.
When omitting the custom allocator, the error did not occur for whatever
reason. I was not able to reproduce the error with a stripped down ".cpp" file.
The error only occurs in my large codebase.
I hope that someone immediately can construct a failing testcase when looking
at my patch.
After debugging, it seems that in stpy_lazy_string_elt_type() a call to
check_typedef has been omitted. The floating point exception disappears after
my fix.
The callstack (synced to 13.2 tag) was:
#0 0x000055e16ad47225 in target_read_string (addr=<error reading variable:
Division by zero>, addr@entry=140614409577184, len=len@entry=5,
width=width@entry=0, fetchlimit=<optimized out>,
buffer=buffer@entry=0x7ffcbb7b9698, bytes_read=bytes_read@entry=0x7ffcbb7b9694)
at ../../gdb/target/target.c:90
#1 0x000055e16adadf4e in val_print_string (elttype=0x55e17793a040,
encoding=0x0, addr=140614409577184, len=5, stream=stream@entry=0x55e16c409b60,
options=options@entry=0x7ffcbb7b9820) at ../../gdb/valprint.c:2624
#2 0x000055e16ac0f513 in print_string_repr (gdbarch=0x55e16c610a20,
language=0x55e16b44aaf0 <cplus_language_defn>, options=0x7ffcbb7b9970,
recurse=0, stream=0x55e16c409b60, hint=0x55e16c61e6b0 "string",
printer=<optimized out>) at ../../gdb/python/py-prettyprint.c:307
#3 gdbpy_apply_val_pretty_printer (extlang=<optimized out>, value=<optimized
out>, stream=0x55e16c409b60, recurse=0, options=0x7ffcbb7b9970,
language=0x55e16b44aaf0 <cplus_language_defn>) at
../../gdb/python/py-prettyprint.c:618
#4 0x000055e16aa4de1d in apply_ext_lang_val_pretty_printer
(val=val@entry=0x55e17851c8c0, stream=stream@entry=0x55e16c409b60,
recurse=recurse@entry=0, options=options@entry=0x7ffcbb7b9970,
language=0x55e16b44aaf0 <cplus_language_defn>) at ../../gdb/extension.c:489
#5 0x000055e16adab33b in value_print (val=val@entry=0x55e17851c8c0,
stream=0x55e16c409b60, options=options@entry=0x7ffcbb7b9970) at
../../gdb/valprint.c:1184
#6 0x000055e16abc740f in print_formatted (val=val@entry=0x55e17851c8c0,
size=size@entry=0, options=options@entry=0x7ffcbb7b9970, stream=<optimized
out>) at ../../gdb/printcmd.c:337
#7 0x000055e16abca7cd in print_value (val=val@entry=0x55e17851c8c0, opts=...)
at ../../gdb/printcmd.c:1252
Please find my patch in the attachment.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug python/31805] Division by zero in target_read_string()
2024-05-27 11:47 [Bug python/31805] New: Division by zero in target_read_string() kkilger at gmail dot com
@ 2024-05-27 16:08 ` kkilger at gmail dot com
2024-05-29 22:02 ` ssbssa at sourceware dot org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: kkilger at gmail dot com @ 2024-05-27 16:08 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=31805
Kilian Kilger <kkilger at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kkilger at gmail dot com
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug python/31805] Division by zero in target_read_string()
2024-05-27 11:47 [Bug python/31805] New: Division by zero in target_read_string() kkilger at gmail dot com
2024-05-27 16:08 ` [Bug python/31805] " kkilger at gmail dot com
@ 2024-05-29 22:02 ` ssbssa at sourceware dot org
2024-05-30 10:32 ` ssbssa at sourceware dot org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: ssbssa at sourceware dot org @ 2024-05-29 22:02 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=31805
Hannes Domani <ssbssa at sourceware dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ssbssa at sourceware dot org
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Last reconfirmed| |2024-05-29
--- Comment #1 from Hannes Domani <ssbssa at sourceware dot org> ---
I can reproduce with this lazy-typedef.c:
```
typedef char MY_CHAR;
const MY_CHAR *str = "something";
int main ()
{
return str[0];
}
```
And with it just try to print 'str' as a lazy string immediately:
```
$ gcc -g -o lazy-typedef lazy-typedef.c
$ gdb -q lazy-typedef
Reading symbols from lazy-typedef...
(gdb) py print(gdb.parse_and_eval("str").lazy_string())
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
```
I can confirm that your patch fixes the problem for me as well:
```
$ gdb -q lazy-typedef
Reading symbols from lazy-typedef...
(gdb) py print(gdb.parse_and_eval("str").lazy_string())
"something"
(gdb)
```
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug python/31805] Division by zero in target_read_string()
2024-05-27 11:47 [Bug python/31805] New: Division by zero in target_read_string() kkilger at gmail dot com
2024-05-27 16:08 ` [Bug python/31805] " kkilger at gmail dot com
2024-05-29 22:02 ` ssbssa at sourceware dot org
@ 2024-05-30 10:32 ` ssbssa at sourceware dot org
2024-06-11 16:08 ` tromey at sourceware dot org
2024-06-12 14:07 ` tromey at sourceware dot org
4 siblings, 0 replies; 6+ messages in thread
From: ssbssa at sourceware dot org @ 2024-05-30 10:32 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=31805
--- Comment #2 from Hannes Domani <ssbssa at sourceware dot org> ---
You get basically the same crash with this example:
```
struct incomplete *inco = (struct incomplete*)0x1;
```
It doesn't make any sense, but you can try to convert it to a lazy string as
well:
```
$ gcc -g -c lazy-incomplete.c
$ gdb -q lazy-incomplete.o
Reading symbols from lazy-incomplete.o...
(gdb) py print(gdb.parse_and_eval("inco").lazy_string())
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
```
And the patch does not fix this one.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug python/31805] Division by zero in target_read_string()
2024-05-27 11:47 [Bug python/31805] New: Division by zero in target_read_string() kkilger at gmail dot com
` (2 preceding siblings ...)
2024-05-30 10:32 ` ssbssa at sourceware dot org
@ 2024-06-11 16:08 ` tromey at sourceware dot org
2024-06-12 14:07 ` tromey at sourceware dot org
4 siblings, 0 replies; 6+ messages in thread
From: tromey at sourceware dot org @ 2024-06-11 16:08 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=31805
Tom Tromey <tromey at sourceware dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Target Milestone|--- |16.1
CC| |tromey at sourceware dot org
Status|NEW |RESOLVED
--- Comment #3 from Tom Tromey <tromey at sourceware dot org> ---
I pushed the fix for this but forgot to add a Bug: trailer.
https://sourceware.org/pipermail/gdb-patches/2024-May/209399.html
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug python/31805] Division by zero in target_read_string()
2024-05-27 11:47 [Bug python/31805] New: Division by zero in target_read_string() kkilger at gmail dot com
` (3 preceding siblings ...)
2024-06-11 16:08 ` tromey at sourceware dot org
@ 2024-06-12 14:07 ` tromey at sourceware dot org
4 siblings, 0 replies; 6+ messages in thread
From: tromey at sourceware dot org @ 2024-06-12 14:07 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=31805
Tom Tromey <tromey at sourceware dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|16.1 |15.1
--- Comment #4 from Tom Tromey <tromey at sourceware dot org> ---
I'm checking this in on the gdb-15 branch as well now.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-06-12 14:07 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-27 11:47 [Bug python/31805] New: Division by zero in target_read_string() kkilger at gmail dot com
2024-05-27 16:08 ` [Bug python/31805] " kkilger at gmail dot com
2024-05-29 22:02 ` ssbssa at sourceware dot org
2024-05-30 10:32 ` ssbssa at sourceware dot org
2024-06-11 16:08 ` tromey at sourceware dot org
2024-06-12 14:07 ` tromey 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).