public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: "Maciej W. Rozycki" <macro@embecosm.com>, gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>, Tom Tromey <tom@tromey.com>,
	Richard Bunt <Richard.Bunt@arm.com>
Subject: Re: [PATCH v4 6/6] GDB: Introduce limited array lengths while printing values
Date: Mon, 13 Feb 2023 09:45:32 -0500	[thread overview]
Message-ID: <d70524ae-24cf-6e7c-522b-f365f51203eb@simark.ca> (raw)
In-Reply-To: <alpine.DEB.2.20.2302100126330.7841@tpp.orcam.me.uk>



On 2/10/23 09:19, Maciej W. Rozycki wrote:
> From: Andrew Burgess <andrew.burgess@embecosm.com>
> 
> This commit introduces the idea of loading only part of an array in 
> order to print it, what I call "limited length" arrays.
> 
> The motivation behind this work is to make it possible to print slices 
> of very large arrays, where very large means bigger than 
> `max-value-size'.
> 
> Consider this GDB session with the current GDB:
> 
>   (gdb) set max-value-size 100
>   (gdb) p large_1d_array
>   value requires 400 bytes, which is more than max-value-size
>   (gdb) p -elements 10 -- large_1d_array
>   value requires 400 bytes, which is more than max-value-size
> 
> notice that the request to print 10 elements still fails, even though 10 
> elements should be less than the max-value-size.  With a patched version 
> of GDB:
> 
>   (gdb) p -elements 10 -- large_1d_array
>   $1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9...}
> 
> So now the print has succeeded.  It also has loaded `max-value-size' 
> worth of data into value history, so the recorded value can be accessed 
> consistently:
> 
>   (gdb) p -elements 10 -- $1
>   $2 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9...}
>   (gdb) p $1
>   $3 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
>     20, 21, 22, 23, 24, <unavailable> <repeats 75 times>}
>   (gdb)
> 
> Accesses with other languages work similarly, although for Ada only 
> C-style [] array element/dimension accesses use history.  For both Ada 
> and Fortran () array element/dimension accesses go straight to the 
> inferior, bypassing the value history just as with C pointers.
> 
> Co-Authored-By: Maciej W. Rozycki <macro@embecosm.com>
> ---
> Changes from v3:
> 
> - Rework changes to `record_latest_value' following the removal of code to 
>   mark outside ranges unavailable.
> 
> - Update `set_limited_array_length' introductory comment.
> 
> - Rebase NEWS update following GDB 13 branching.
> 
> Changes from v2:
> 
> - Adjust for the `value_copy' update in 1/5.
> 
> - Remove the handling of (dst_len != src_len) in `value_copy' where
>   `dst_len' is always the same as `src_len' (from the corresponding 
>   settings in `val' assigned to from `arg' right beforehand).
> 
> - Switch Ada and Fortran test cases to using `allow_ada_tests' and 
>   `allow_fortran_tests' respectively.
> 
> - Fix a couple of formatting issues involving spaces used instead of tabs.
> 
> Changes from v1:
> 
> - Load `max-value-size' worth data into the value history for limited 
>   length accesses and mark the area beyond unavailable.
> 
> - Handle the `output' command.
> 
> - Expand test coverage.

I see:

print -elements 2 -- Large_3d_Array
=================================================================
==25757==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60d000028ed4 at pc 0x7f3ee9c5efd6 bp 0x7ffe215215b0 sp 0x7ffe21520d58
READ of size 64 at 0x60d000028ed4 thread T0
    #0 0x7f3ee9c5efd5 in __interceptor_memmove /usr/src/debug/gcc/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:810
    #1 0x563e8a43bca1 in unsigned char* std::__copy_move<false, true, std::random_access_iterator_tag>::__copy_m<unsigned char>(unsigned char const*, unsigned char const*, unsigned char*) /usr/include/c++/12.2.1/bits/stl_algobase.h:431
    #2 0x563e8a56df07 in unsigned char* std::__copy_move_a2<false, unsigned char const*, unsigned char*>(unsigned char const*, unsigned char const*, unsigned char*) /usr/include/c++/12.2.1/bits/stl_algobase.h:495
    #3 0x563e8a558ada in unsigned char* std::__copy_move_a1<false, unsigned char const*, unsigned char*>(unsigned char const*, unsigned char const*, unsigned char*) /usr/include/c++/12.2.1/bits/stl_algobase.h:522
    #4 0x563e8a538725 in unsigned char* std::__copy_move_a<false, unsigned char const*, unsigned char*>(unsigned char const*, unsigned char const*, unsigned char*) /usr/include/c++/12.2.1/bits/stl_algobase.h:529
    #5 0x563e8a517cda in unsigned char* std::copy<unsigned char const*, unsigned char*>(unsigned char const*, unsigned char const*, unsigned char*) /usr/include/c++/12.2.1/bits/stl_algobase.h:620
    #6 0x563e8a4facff in void gdb::copy<unsigned char const, unsigned char>(gdb::array_view<unsigned char const>, gdb::array_view<unsigned char>) /home/simark/src/binutils-gdb/gdb/../gdbsupport/array-view.h:219
    #7 0x563e8d14c6ea in value_contents_copy_raw /home/simark/src/binutils-gdb/gdb/value.c:1512
    #8 0x563e8d14ced7 in value_contents_copy(value*, long, value*, long, long) /home/simark/src/binutils-gdb/gdb/value.c:1578
    #9 0x563e8d1626fc in value_from_component(value*, type*, long) /home/simark/src/binutils-gdb/gdb/value.c:3991
    #10 0x563e8d16291a in value_from_component_bitsize(value*, type*, long, long) /home/simark/src/binutils-gdb/gdb/value.c:4015
    #11 0x563e8d12c000 in value_print_array_elements(value*, ui_file*, int, value_print_options const*, unsigned int) /home/simark/src/binutils-gdb/gdb/valprint.c:2027
    #12 0x563e8a6145a5 in ada_value_print_array /home/simark/src/binutils-gdb/gdb/ada-valprint.c:931
    #13 0x563e8a615207 in ada_value_print_inner(value*, ui_file*, int, value_print_options const*) /home/simark/src/binutils-gdb/gdb/ada-valprint.c:1075
    #14 0x563e8a4efd35 in ada_language::value_print_inner(value*, ui_file*, int, value_print_options const*) const /home/simark/src/binutils-gdb/gdb/ada-lang.c:13793
    #15 0x563e8d125457 in common_val_print(value*, ui_file*, int, value_print_options const*, language_defn const*) /home/simark/src/binutils-gdb/gdb/valprint.c:1094
    #16 0x563e8a615979 in ada_value_print(value*, ui_file*, value_print_options const*) /home/simark/src/binutils-gdb/gdb/ada-valprint.c:1133
    #17 0x563e8a4efd00 in ada_language::value_print(value*, ui_file*, value_print_options const*) const /home/simark/src/binutils-gdb/gdb/ada-lang.c:13784
    #18 0x563e8d1266a1 in value_print(value*, ui_file*, value_print_options const*) /home/simark/src/binutils-gdb/gdb/valprint.c:1211
    #19 0x563e8c169299 in print_formatted /home/simark/src/binutils-gdb/gdb/printcmd.c:337
    #20 0x563e8c1708e4 in print_value(value*, value_print_options const&) /home/simark/src/binutils-gdb/gdb/printcmd.c:1258
    #21 0x563e8c1713e2 in print_command_1 /home/simark/src/binutils-gdb/gdb/printcmd.c:1372
    #22 0x563e8c171ee7 in print_command /home/simark/src/binutils-gdb/gdb/printcmd.c:1463
    #23 0x563e8ac9adba in do_simple_func /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:95
    #24 0x563e8acb1aa8 in cmd_func(cmd_list_element*, char const*, int) /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:2737
    #25 0x563e8cc7f8aa in execute_command(char const*, int) /home/simark/src/binutils-gdb/gdb/top.c:688
    #26 0x563e8b69f9b6 in command_handler(char const*) /home/simark/src/binutils-gdb/gdb/event-top.c:620
    #27 0x563e8b6a0c93 in command_line_handler(std::unique_ptr<char, gdb::xfree_deleter<char> >&&) /home/simark/src/binutils-gdb/gdb/event-top.c:856
    #28 0x563e8cdce8b8 in tui_command_line_handler /home/simark/src/binutils-gdb/gdb/tui/tui-interp.c:104
    #29 0x563e8b69d8a9 in gdb_rl_callback_handler /home/simark/src/binutils-gdb/gdb/event-top.c:250
    #30 0x563e8d2d88a8 in rl_callback_read_char /home/simark/src/binutils-gdb/readline/readline/callback.c:290
    #31 0x563e8b69d29f in gdb_rl_callback_read_char_wrapper_noexcept /home/simark/src/binutils-gdb/gdb/event-top.c:192
    #32 0x563e8b69d4f7 in gdb_rl_callback_read_char_wrapper /home/simark/src/binutils-gdb/gdb/event-top.c:225
    #33 0x563e8b69eeb6 in stdin_event_handler /home/simark/src/binutils-gdb/gdb/event-top.c:545
    #34 0x563e8d680339 in handle_file_event /home/simark/src/binutils-gdb/gdbsupport/event-loop.cc:573
    #35 0x563e8d680c7f in gdb_wait_for_event /home/simark/src/binutils-gdb/gdbsupport/event-loop.cc:694
    #36 0x563e8d67e940 in gdb_do_one_event(int) /home/simark/src/binutils-gdb/gdbsupport/event-loop.cc:264
    #37 0x563e8bdd8f65 in start_event_loop /home/simark/src/binutils-gdb/gdb/main.c:411
    #38 0x563e8bdd93cb in captured_command_loop /home/simark/src/binutils-gdb/gdb/main.c:471
    #39 0x563e8bdde775 in captured_main /home/simark/src/binutils-gdb/gdb/main.c:1310
    #40 0x563e8bdde852 in gdb_main(captured_main_args*) /home/simark/src/binutils-gdb/gdb/main.c:1325
    #41 0x563e8a39759d in main /home/simark/src/binutils-gdb/gdb/gdb.c:32
    #42 0x7f3ee863c78f  (/usr/lib/libc.so.6+0x2378f)
    #43 0x7f3ee863c849 in __libc_start_main (/usr/lib/libc.so.6+0x23849)
    #44 0x563e8a397364 in _start (/home/simark/build/binutils-gdb/gdb/gdb+0xabae364)

0x60d000028ed4 is located 0 bytes to the right of 132-byte region [0x60d000028e50,0x60d000028ed4)
allocated by thread T0 here:
    #0 0x7f3ee9cbf411 in __interceptor_calloc /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x563e8a62c4ec in xcalloc /home/simark/src/binutils-gdb/gdb/alloc.c:97
    #2 0x563e8d66cfff in xzalloc(unsigned long) /home/simark/src/binutils-gdb/gdbsupport/common-utils.cc:29
    #3 0x563e8d149569 in allocate_value_contents /home/simark/src/binutils-gdb/gdb/value.c:1179
    #4 0x563e8d1659e5 in value_fetch_lazy(value*) /home/simark/src/binutils-gdb/gdb/value.c:4354
    #5 0x563e8d1546f5 in record_latest_value(value*) /home/simark/src/binutils-gdb/gdb/value.c:2099
    #6 0x563e8c170833 in print_value(value*, value_print_options const&) /home/simark/src/binutils-gdb/gdb/printcmd.c:1250
    #7 0x563e8c1713e2 in print_command_1 /home/simark/src/binutils-gdb/gdb/printcmd.c:1372
    #8 0x563e8c171ee7 in print_command /home/simark/src/binutils-gdb/gdb/printcmd.c:1463
    #9 0x563e8ac9adba in do_simple_func /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:95
    #10 0x563e8acb1aa8 in cmd_func(cmd_list_element*, char const*, int) /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:2737
    #11 0x563e8cc7f8aa in execute_command(char const*, int) /home/simark/src/binutils-gdb/gdb/top.c:688
    #12 0x563e8b69f9b6 in command_handler(char const*) /home/simark/src/binutils-gdb/gdb/event-top.c:620
    #13 0x563e8b6a0c93 in command_line_handler(std::unique_ptr<char, gdb::xfree_deleter<char> >&&) /home/simark/src/binutils-gdb/gdb/event-top.c:856
    #14 0x563e8cdce8b8 in tui_command_line_handler /home/simark/src/binutils-gdb/gdb/tui/tui-interp.c:104
    #15 0x563e8b69d8a9 in gdb_rl_callback_handler /home/simark/src/binutils-gdb/gdb/event-top.c:250
    #16 0x563e8d2d88a8 in rl_callback_read_char /home/simark/src/binutils-gdb/readline/readline/callback.c:290
    #17 0x563e8b69d29f in gdb_rl_callback_read_char_wrapper_noexcept /home/simark/src/binutils-gdb/gdb/event-top.c:192
    #18 0x563e8b69d4f7 in gdb_rl_callback_read_char_wrapper /home/simark/src/binutils-gdb/gdb/event-top.c:225
    #19 0x563e8b69eeb6 in stdin_event_handler /home/simark/src/binutils-gdb/gdb/event-top.c:545
    #20 0x563e8d680339 in handle_file_event /home/simark/src/binutils-gdb/gdbsupport/event-loop.cc:573
    #21 0x563e8d680c7f in gdb_wait_for_event /home/simark/src/binutils-gdb/gdbsupport/event-loop.cc:694
    #22 0x563e8d67e940 in gdb_do_one_event(int) /home/simark/src/binutils-gdb/gdbsupport/event-loop.cc:264
    #23 0x563e8bdd8f65 in start_event_loop /home/simark/src/binutils-gdb/gdb/main.c:411
    #24 0x563e8bdd93cb in captured_command_loop /home/simark/src/binutils-gdb/gdb/main.c:471
    #25 0x563e8bdde775 in captured_main /home/simark/src/binutils-gdb/gdb/main.c:1310
    #26 0x563e8bdde852 in gdb_main(captured_main_args*) /home/simark/src/binutils-gdb/gdb/main.c:1325
    #27 0x563e8a39759d in main /home/simark/src/binutils-gdb/gdb/gdb.c:32
    #28 0x7f3ee863c78f  (/usr/lib/libc.so.6+0x2378f)

Simon

  reply	other threads:[~2023-02-13 14:45 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-10 14:18 [PATCH v4 0/6] gdb: introduce " Maciej W. Rozycki
2023-02-10 14:19 ` [PATCH v4 1/6] GDB: Switch to using C++ standard integer type limits Maciej W. Rozycki
2023-02-10 21:13   ` Tom Tromey
2023-02-10 14:19 ` [PATCH v4 2/6] GDB: Ignore `max-value-size' setting with value history accesses Maciej W. Rozycki
2023-02-10 14:19 ` [PATCH v4 3/6] GDB: Fix the mess with value byte/bit range types Maciej W. Rozycki
2023-02-10 14:19 ` [PATCH v4 4/6] GDB: Only make data actually retrieved into value history available Maciej W. Rozycki
2023-02-10 21:16   ` Tom Tromey
2023-02-10 14:19 ` [PATCH v4 5/6] GDB/testsuite: Add `-nonl' option to `gdb_test' Maciej W. Rozycki
2023-02-10 14:19 ` [PATCH v4 6/6] GDB: Introduce limited array lengths while printing values Maciej W. Rozycki
2023-02-13 14:45   ` Simon Marchi [this message]
2023-02-14 19:20     ` Maciej W. Rozycki
2023-02-23 21:16       ` Maciej W. Rozycki
2023-02-10 21:17 ` [PATCH v4 0/6] gdb: introduce " Tom Tromey
2023-02-10 23:50   ` Maciej W. Rozycki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d70524ae-24cf-6e7c-522b-f365f51203eb@simark.ca \
    --to=simark@simark.ca \
    --cc=Richard.Bunt@arm.com \
    --cc=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=macro@embecosm.com \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).