From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11773 invoked by alias); 14 Jan 2014 08:04:46 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 11748 invoked by uid 89); 14 Jan 2014 08:04:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mga11.intel.com Received: from mga11.intel.com (HELO mga11.intel.com) (192.55.52.93) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 14 Jan 2014 08:04:44 +0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 14 Jan 2014 00:04:42 -0800 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga002.fm.intel.com with ESMTP; 14 Jan 2014 00:04:40 -0800 Received: from ulvlx001.iul.intel.com (ulvlx001.iul.intel.com [172.28.207.17]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id s0E84eKP013285; Tue, 14 Jan 2014 08:04:40 GMT Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id s0E84eTp009366; Tue, 14 Jan 2014 09:04:40 +0100 Received: (from mmetzger@localhost) by ulvlx001.iul.intel.com with œ id s0E84eiG009362; Tue, 14 Jan 2014 09:04:40 +0100 From: Markus Metzger To: jan.kratochvil@redhat.com, palves@redhat.com Cc: gdb-patches@sourceware.org Subject: [PATCH v10 08/28] record-btrace: start counting at one Date: Tue, 14 Jan 2014 08:05:00 -0000 Message-Id: <1389686678-9039-9-git-send-email-markus.t.metzger@intel.com> In-Reply-To: <1389686678-9039-1-git-send-email-markus.t.metzger@intel.com> References: <1389686678-9039-1-git-send-email-markus.t.metzger@intel.com> X-IsSubscribed: yes X-SW-Source: 2014-01/txt/msg00401.txt.bz2 The record instruction-history and record-function-call-history commands start counting instructions at zero. This is somewhat unintuitive when we start navigating in the recorded instruction history. Start at one, instead. Reviewed-by: Eli Zaretskii 2014-01-14 Markus Metzger * btrace.c (ftrace_new_function): Start counting at one. testsuite/ * gdb.btrace/instruction_history.exp: Update. * gdb.btrace/function_call_history.exp: Update. --- gdb/NEWS | 4 + gdb/btrace.c | 8 +- gdb/record-btrace.c | 4 +- gdb/testsuite/gdb.btrace/function_call_history.exp | 156 ++++++++++----------- gdb/testsuite/gdb.btrace/instruction_history.exp | 67 ++++----- 5 files changed, 125 insertions(+), 114 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 00defe1..02d541b 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -39,6 +39,10 @@ * New script contrib/gdb-add-index.sh for adding .gdb_index sections to binaries. +* The 'record instruction-history' command now starts counting instructions + at one. This also affects the instruction ranges reported by the + 'record function-call-history' command when given the /i modifier. + * Python scripting ** Frame filters and frame decorators have been added. diff --git a/gdb/btrace.c b/gdb/btrace.c index 5bda127..2e9e008 100644 --- a/gdb/btrace.c +++ b/gdb/btrace.c @@ -208,7 +208,13 @@ ftrace_new_function (struct btrace_function *prev, bfun->lbegin = INT_MAX; bfun->lend = INT_MIN; - if (prev != NULL) + if (prev == NULL) + { + /* Start counting at one. */ + bfun->number = 1; + bfun->insn_offset = 1; + } + else { gdb_assert (prev->flow.next == NULL); prev->flow.next = bfun; diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index 875b138..116cf1d 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -227,11 +227,11 @@ record_btrace_info (void) btrace_call_end (&call, btinfo); btrace_call_prev (&call, 1); - calls = btrace_call_number (&call) + 1; + calls = btrace_call_number (&call); btrace_insn_end (&insn, btinfo); btrace_insn_prev (&insn, 1); - insns = btrace_insn_number (&insn) + 1; + insns = btrace_insn_number (&insn); } printf_unfiltered (_("Recorded %u instructions in %u functions for thread " diff --git a/gdb/testsuite/gdb.btrace/function_call_history.exp b/gdb/testsuite/gdb.btrace/function_call_history.exp index bf2458b..cd94dec 100644 --- a/gdb/testsuite/gdb.btrace/function_call_history.exp +++ b/gdb/testsuite/gdb.btrace/function_call_history.exp @@ -38,28 +38,28 @@ gdb_breakpoint $bp_location gdb_continue_to_breakpoint "cont to $bp_location" ".*$testfile.c:$bp_location.*" proc rec_fun_all {} { - gdb_test "record function-call-history 0" [join [list \ - "0\tmain" \ - "1\tinc" \ - "2\tmain" \ - "3\tinc" \ - "4\tmain" \ - "5\tinc" \ - "6\tmain" \ - "7\tinc" \ - "8\tmain" \ - "9\tinc" \ - "10\tmain" \ - "11\tinc" \ - "12\tmain" \ - "13\tinc" \ - "14\tmain" \ - "15\tinc" \ - "16\tmain" \ - "17\tinc" \ - "18\tmain" \ - "19\tinc" \ - "20\tmain"] "\r\n"] + gdb_test "record function-call-history 1" [join [list \ + "1\tmain" \ + "2\tinc" \ + "3\tmain" \ + "4\tinc" \ + "5\tmain" \ + "6\tinc" \ + "7\tmain" \ + "8\tinc" \ + "9\tmain" \ + "10\tinc" \ + "11\tmain" \ + "12\tinc" \ + "13\tmain" \ + "14\tinc" \ + "15\tmain" \ + "16\tinc" \ + "17\tmain" \ + "18\tinc" \ + "19\tmain" \ + "20\tinc" \ + "21\tmain"] "\r\n"] } # show function call history with unlimited size, we expect to see all 21 entries @@ -72,31 +72,31 @@ with_test_prefix "size 21" rec_fun_all # show first 15 entries gdb_test_no_output "set record function-call-history-size 15" -gdb_test "record function-call-history 0" [join [list \ - "0\tmain" \ - "1\tinc" \ - "2\tmain" \ - "3\tinc" \ - "4\tmain" \ - "5\tinc" \ - "6\tmain" \ - "7\tinc" \ - "8\tmain" \ - "9\tinc" \ - "10\tmain" \ - "11\tinc" \ - "12\tmain" \ - "13\tinc" \ - "14\tmain"] "\r\n"] "forward - 1" +gdb_test "record function-call-history 1" [join [list \ + "1\tmain" \ + "2\tinc" \ + "3\tmain" \ + "4\tinc" \ + "5\tmain" \ + "6\tinc" \ + "7\tmain" \ + "8\tinc" \ + "9\tmain" \ + "10\tinc" \ + "11\tmain" \ + "12\tinc" \ + "13\tmain" \ + "14\tinc" \ + "15\tmain"] "\r\n"] "forward - 1" # show last 6 entries gdb_test "record function-call-history +" [join [list \ - "15\tinc" \ - "16\tmain" \ - "17\tinc" \ - "18\tmain" \ - "19\tinc" \ - "20\tmain"] "\r\n"] "forward - 2" + "16\tinc" \ + "17\tmain" \ + "18\tinc" \ + "19\tmain" \ + "20\tinc" \ + "21\tmain"] "\r\n"] "forward - 2" # moving further should not work gdb_test "record function-call-history +" "At the end of the branch trace record\\." "forward - 3" @@ -106,30 +106,30 @@ gdb_test "record function-call-history +" "At the end of the branch trace record # moving back showing the latest 15 function calls gdb_test "record function-call-history -" [join [list \ - "6\tmain" \ - "7\tinc" \ - "8\tmain" \ - "9\tinc" \ - "10\tmain" \ - "11\tinc" \ - "12\tmain" \ - "13\tinc" \ - "14\tmain" \ - "15\tinc" \ - "16\tmain" \ - "17\tinc" \ - "18\tmain" \ - "19\tinc" \ - "20\tmain"] "\r\n"] "backward - 1" + "7\tmain" \ + "8\tinc" \ + "9\tmain" \ + "10\tinc" \ + "11\tmain" \ + "12\tinc" \ + "13\tmain" \ + "14\tinc" \ + "15\tmain" \ + "16\tinc" \ + "17\tmain" \ + "18\tinc" \ + "19\tmain" \ + "20\tinc" \ + "21\tmain"] "\r\n"] "backward - 1" # moving further back shows the 6 first function calls gdb_test "record function-call-history -" [join [list \ - "0\tmain" \ - "1\tinc" \ - "2\tmain" \ - "3\tinc" \ - "4\tmain" \ - "5\tinc"] "\r\n"] "backward - 2" + "1\tmain" \ + "2\tinc" \ + "3\tmain" \ + "4\tinc" \ + "5\tmain" \ + "6\tinc"] "\r\n"] "backward - 2" # moving further back shouldn't work gdb_test "record function-call-history -" "At the start of the branch trace record\\." "backward - 3" @@ -169,18 +169,18 @@ gdb_test "record function-call-history /l +" "At the end of the branch trace rec gdb_test "record function-call-history /l" "At the end of the branch trace record\\." "forward /l - 4" set expected_range [join [list \ - "3\tinc" \ - "4\tmain" \ - "5\tinc" \ - "6\tmain" \ - "7\tinc" \ - "8\tmain" \ - "9\tinc"] "\r\n"] + "4\tinc" \ + "5\tmain" \ + "6\tinc" \ + "7\tmain" \ + "8\tinc" \ + "9\tmain" \ + "10\tinc"] "\r\n"] # show functions in instruction range -gdb_test "record function-call-history 3,10" $expected_range -gdb_test "record function-call-history 3,+7" $expected_range -gdb_test "record function-call-history 10,-7" $expected_range +gdb_test "record function-call-history 4,11" $expected_range +gdb_test "record function-call-history 4,+7" $expected_range +gdb_test "record function-call-history 11,-7" $expected_range # set bp after fib recursion and continue set bp_location [gdb_get_line_number "bp.2" $testfile.c] @@ -191,8 +191,7 @@ gdb_continue_to_breakpoint "cont to $bp_location" ".*$testfile.c:$bp_location.*" # so we limit the output to only show the latest 11 function calls gdb_test_no_output "set record function-call-history-size 11" gdb_test "record function-call-history" [join [list \ - "20\tmain" \ - "21\tfib" \ + "21\tmain" \ "22\tfib" \ "23\tfib" \ "24\tfib" \ @@ -201,4 +200,5 @@ gdb_test "record function-call-history" [join [list \ "27\tfib" \ "28\tfib" \ "29\tfib" \ - "30\tmain"] "\r\n"] "recursive" + "30\tfib" \ + "31\tmain"] "\r\n"] "recursive" diff --git a/gdb/testsuite/gdb.btrace/instruction_history.exp b/gdb/testsuite/gdb.btrace/instruction_history.exp index c6f6500..46ef65e 100644 --- a/gdb/testsuite/gdb.btrace/instruction_history.exp +++ b/gdb/testsuite/gdb.btrace/instruction_history.exp @@ -65,36 +65,37 @@ if { $traced != 6 } { } # test that we see the expected instructions -gdb_test "record instruction-history 1,6" [join [list \ - "1\t 0x\[0-9a-f\]+ :\tje 0x\[0-9a-f\]+ " \ - "2\t 0x\[0-9a-f\]+ :\tdec %eax" \ - "3\t 0x\[0-9a-f\]+ :\tjmp 0x\[0-9a-f\]+ " \ - "4\t 0x\[0-9a-f\]+ :\tcmp \\\$0x0,%eax" \ - "5\t 0x\[0-9a-f\]+ :\tje 0x\[0-9a-f\]+ "] "\r\n"] - -gdb_test "record instruction-history /f 1,+5" [join [list \ - "1\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ " \ - "2\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tdec %eax" \ - "3\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ " \ - "4\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tcmp \\\$0x0,%eax" \ - "5\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ \r" \ -] "\r\n"] - -gdb_test "record instruction-history /p 6,-5" [join [list \ - "1\t0x\[0-9a-f\]+ :\tje 0x\[0-9a-f\]+ " \ - "2\t0x\[0-9a-f\]+ :\tdec %eax" \ - "3\t0x\[0-9a-f\]+ :\tjmp 0x\[0-9a-f\]+ " \ - "4\t0x\[0-9a-f\]+ :\tcmp \\\$0x0,%eax" \ - "5\t0x\[0-9a-f\]+ :\tje 0x\[0-9a-f\]+ \r" \ -] "\r\n"] - -gdb_test "record instruction-history /pf 1,6" [join [list \ - "1\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ " \ - "2\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tdec %eax" \ - "3\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ " \ - "4\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tcmp \\\$0x0,%eax" \ - "5\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ \r" \ -] "\r\n"] +gdb_test "record instruction-history 2,7" [join [list \ + "2\t 0x\[0-9a-f\]+ :\tje 0x\[0-9a-f\]+ " \ + "3\t 0x\[0-9a-f\]+ :\tdec %eax" \ + "4\t 0x\[0-9a-f\]+ :\tjmp 0x\[0-9a-f\]+ " \ + "5\t 0x\[0-9a-f\]+ :\tcmp \\\$0x0,%eax" \ + "6\t 0x\[0-9a-f\]+ :\tje 0x\[0-9a-f\]+ \r" \ + ] "\r\n"] + +gdb_test "record instruction-history /f 2,+5" [join [list \ + "2\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ " \ + "3\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tdec %eax" \ + "4\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ " \ + "5\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tcmp \\\$0x0,%eax" \ + "6\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ \r" \ + ] "\r\n"] + +gdb_test "record instruction-history /p 7,-5" [join [list \ + "2\t0x\[0-9a-f\]+ :\tje 0x\[0-9a-f\]+ " \ + "3\t0x\[0-9a-f\]+ :\tdec %eax" \ + "4\t0x\[0-9a-f\]+ :\tjmp 0x\[0-9a-f\]+ " \ + "5\t0x\[0-9a-f\]+ :\tcmp \\\$0x0,%eax" \ + "6\t0x\[0-9a-f\]+ :\tje 0x\[0-9a-f\]+ \r" \ + ] "\r\n"] + +gdb_test "record instruction-history /pf 2,7" [join [list \ + "2\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ " \ + "3\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tdec %eax" \ + "4\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ " \ + "5\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tcmp \\\$0x0,%eax" \ + "6\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ \r" \ + ] "\r\n"] # the following tests are checking the iterators # to avoid lots of regexps, we just check the number of lines that @@ -120,7 +121,7 @@ proc test_lines_length { command message } { # all $traced instructions gdb_test_no_output "set record instruction-history-size 0" set message "record instruction-history - unlimited" -set lines [test_lines_length "record instruction-history 0" $message] +set lines [test_lines_length "record instruction-history 1" $message] if { $traced != $lines } { fail $message } else { @@ -129,7 +130,7 @@ if { $traced != $lines } { gdb_test_no_output "set record instruction-history-size $traced" set message "record instruction-history - traced" -set lines [test_lines_length "record instruction-history 0" $message] +set lines [test_lines_length "record instruction-history 1" $message] if { $traced != $lines } { fail $message } else { @@ -140,7 +141,7 @@ if { $traced != $lines } { set history_size 3 gdb_test_no_output "set record instruction-history-size $history_size" set message "browse history forward start" -set lines [test_lines_length "record instruction-history 0" $message] +set lines [test_lines_length "record instruction-history 1" $message] if { $lines != $history_size } { fail $message } else { -- 1.8.3.1