Bug 16196 - lazy string vs "print elements"
Summary: lazy string vs "print elements"
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: python (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-20 21:28 UTC by dje
Modified: 2024-11-18 19:47 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description dje 2013-11-20 21:28:51 UTC
Bug 10633 says this is fixed, and the printing may be, but there's an optimization to be had here.
read_string doesn't obey fetchlimit if len != -1.
So if one is printing an uninitialized string, or just a very long string,
gdb will read the whole thing, even if "print elements" is much smaller.

Plus I found another issue:
- long -> int conversion in the extracted lazy string length loses precision
  [which while one wouldn't expect to have 4G strings, pretty printing an uninitialized object should have more consistent behaviour]

Repro:
create long c++ string, set target debug 1, and print the string.
How many bytes are read from the target?
Comment 1 dje 2013-11-22 20:32:48 UTC
If partial_memory_read fails, it will fall back to a byte at a time.
This can be really painful on remote targets.
Maybe it would make sense to at least read 8 bytes at a time (that's what read_string does), until that fails or len < 8, and then read a byte at a time.
[One could even try larger chunks first, but I think it would be ok to at least start with 8 bytes at a time.]
Comment 2 Sourceware Commits 2013-11-22 22:01:21 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gdb and binutils".

The branch, master has been updated
       via  f380848e84613364a17008f04e91bfef09eaf158 (commit)
      from  c0621699ffdbeea387ea37a90258939540b26424 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f380848e84613364a17008f04e91bfef09eaf158

commit f380848e84613364a17008f04e91bfef09eaf158
Author: Sterling Augustine <saugustine@google.com>
Date:   Fri Nov 22 13:55:32 2013 -0800

    2013-11-22  Sterling Augustine  <saugustine@google.com>
    
         PR gdb/16196:
         * valprint.c (read_string): Set new variable fetchlen based on
         fetchlimit and size.  Use it in call to partial_memory_read.
         Update comment.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog  |    7 +++++++
 gdb/valprint.c |   18 +++++++++++-------
 2 files changed, 18 insertions(+), 7 deletions(-)
Comment 3 Sourceware Commits 2013-11-22 22:25:44 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gdb and binutils".

The branch, master has been updated
       via  38e1f2a7d503d8abd788456782287383e0a0cfe8 (commit)
      from  f380848e84613364a17008f04e91bfef09eaf158 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=38e1f2a7d503d8abd788456782287383e0a0cfe8

commit 38e1f2a7d503d8abd788456782287383e0a0cfe8
Author: Sterling Augustine <saugustine@google.com>
Date:   Fri Nov 22 13:55:32 2013 -0800

    2013-11-22  Sterling Augustine  <saugustine@google.com>
    
         PR gdb/16196:
         * valprint.c (read_string): Set new variable fetchlen based on
         fetchlimit and size.  Use it in call to partial_memory_read.
         Update comment.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Comment 4 asmwarrior 2013-11-23 07:20:00 UTC
I'm not sure this bug is related to the bug I reported long time ago:
https://sourceware.org/bugzilla/show_bug.cgi?id=12127

In the bug #12127, I see GDB crash because xmalloc failed if we pass a large random value as its argument, this mostly happens on GDB try to show an un-initiliazed local variable (like std::vector), I have a crash backtrace in https://sourceware.org/bugzilla/attachment.cgi?id=7017, my workaround is a hard-coded patch here: https://sourceware.org/bugzilla/show_bug.cgi?id=12127#c5

Thanks.
Yuanhui Zhang
Comment 5 asmwarrior 2013-11-24 07:33:20 UTC
I add some comments in Bug #12127, see (https://sourceware.org/bugzilla/show_bug.cgi?id=12127#c6), I think the fix in this bug also fix Bug #12127.

Thanks.
Comment 6 Hannes Domani 2023-12-09 13:04:34 UTC
(In reply to Sourceware Commits from comment #2)
> This is an automated email from the git hooks/post-receive script. It was
> generated because a ref change was pushed to the repository containing
> the project "gdb and binutils".
> 
> The branch, master has been updated
>        via  f380848e84613364a17008f04e91bfef09eaf158 (commit)
>       from  c0621699ffdbeea387ea37a90258939540b26424 (commit)
> 
> Those revisions listed above that are new to this repository have
> not appeared on any other notification email; so we list those
> revisions in full, below.
> 
> - Log -----------------------------------------------------------------
> https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;
> h=f380848e84613364a17008f04e91bfef09eaf158
> 
> commit f380848e84613364a17008f04e91bfef09eaf158
> Author: Sterling Augustine <saugustine@google.com>
> Date:   Fri Nov 22 13:55:32 2013 -0800
> 
>     2013-11-22  Sterling Augustine  <saugustine@google.com>
>     
>          PR gdb/16196:
>          * valprint.c (read_string): Set new variable fetchlen based on
>          fetchlimit and size.  Use it in call to partial_memory_read.
>          Update comment.
> 
> -----------------------------------------------------------------------
> 
> Summary of changes:
>  gdb/ChangeLog  |    7 +++++++
>  gdb/valprint.c |   18 +++++++++++-------
>  2 files changed, 18 insertions(+), 7 deletions(-)

Is there still something to do here after this commit?
Comment 7 Tom Tromey 2024-11-18 19:47:20 UTC
I think this is fixed.