From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 11E81385842C for ; Mon, 13 Feb 2023 14:45:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 11E81385842C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca Received: from [10.0.0.11] (unknown [217.28.27.60]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 292B81E0D3; Mon, 13 Feb 2023 09:45:33 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1676299533; bh=58wanDTy5JZvnAYGOohr6/hFv2MLmfmac3fI5UPOy78=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=P7hn5095S/zVzAuiQ59z9rzfgG9hyN+us44tlViNZpho6abqBna9jjHFZdJwpwFkp fFkesZ3dkRsrgtmQoBIAZINM/tkZMQkwg9vE5bykAf/P9h9RojBNWj+Ucobja+NNpq vBEJ+pK0XpYUEs/ifKEUUE2UeaQ39yorR3D4RlHI= Message-ID: Date: Mon, 13 Feb 2023 09:45:32 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: Re: [PATCH v4 6/6] GDB: Introduce limited array lengths while printing values To: "Maciej W. Rozycki" , gdb-patches@sourceware.org Cc: Andrew Burgess , Tom Tromey , Richard Bunt References: Content-Language: en-US From: Simon Marchi In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_PASS,SPF_PASS,TXREP,WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2/10/23 09:19, Maciej W. Rozycki wrote: > From: Andrew Burgess > > 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, } > (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 > --- > 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::__copy_m(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(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(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(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 const*, unsigned char*) /usr/include/c++/12.2.1/bits/stl_algobase.h:620 #6 0x563e8a4facff in void gdb::copy(gdb::array_view, gdb::array_view) /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 >&&) /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 >&&) /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