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

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