From 2ca134ef87b696ea6030d93f45b2486695703362 Mon Sep 17 00:00:00 2001 From: Julien Desfossez Date: Fri, 16 Jun 2017 14:30:30 -0400 Subject: [PATCH] Test debug-info MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add a test program source code, instructions to compile it with the already compiled libhello library, and provide a lttng-ust trace of this program running. The test runs babeltrace on this trace with the --debug-info-target-prefix option set to the tree of babeltrace which allows it to find the debug symbols, and we verify that the text output contains the complete debug_info context structure. Signed-off-by: Julien Desfossez Signed-off-by: Jérémie Galarneau --- .gitignore | 1 + configure.ac | 1 + tests/cli/Makefile.am | 3 +- tests/cli/test_debug_info.in | 34 +++++++++ tests/debug-info-data/README.md | 17 +++++ tests/debug-info-data/main.c | 37 ++++++++++ tests/debug-info-data/trace/metadata | 91 +++++++++++++++++++++++++ tests/debug-info-data/trace/stream_0_0 | Bin 0 -> 292 bytes 8 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 tests/cli/test_debug_info.in create mode 100644 tests/debug-info-data/main.c create mode 100644 tests/debug-info-data/trace/metadata create mode 100644 tests/debug-info-data/trace/stream_0_0 diff --git a/.gitignore b/.gitignore index d7a49b12..f738622d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ /tests/cli/test_packet_seq_num /tests/cli/test_trace_read /tests/cli/test_trace_copy +/tests/cli/test_debug_info /tests/cli/test_convert_args /tests/bin/intersection/bt_python_helper.py /tests/bin/intersection/test_intersection diff --git a/configure.ac b/configure.ac index 323afa75..bdfe76ac 100644 --- a/configure.ac +++ b/configure.ac @@ -542,6 +542,7 @@ AC_CONFIG_FILES([tests/plugins/test-utils-muxer-complete], [chmod +x tests/plugi AC_CONFIG_FILES([tests/cli/test_trace_read], [chmod +x tests/cli/test_trace_read]) AC_CONFIG_FILES([tests/cli/test_trace_copy], [chmod +x tests/cli/test_trace_copy]) +AC_CONFIG_FILES([tests/cli/test_debug_info], [chmod +x tests/cli/test_debug_info]) AC_CONFIG_FILES([tests/cli/intersection/test_intersection], [chmod +x tests/cli/intersection/test_intersection]) AC_CONFIG_FILES([tests/cli/test_convert_args], [chmod +x tests/cli/test_convert_args]) AC_CONFIG_FILES([tests/cli/intersection/bt_python_helper.py]) diff --git a/tests/cli/Makefile.am b/tests/cli/Makefile.am index 27e67dfa..d4437659 100644 --- a/tests/cli/Makefile.am +++ b/tests/cli/Makefile.am @@ -8,7 +8,8 @@ TESTS = test_trace_read \ test_packet_seq_num \ test_convert_args \ intersection/test_intersection \ - test_trace_copy + test_trace_copy \ + test_debug_info if USE_PYTHON TESTS += intersection/test_multi_trace_intersection.py diff --git a/tests/cli/test_debug_info.in b/tests/cli/test_debug_info.in new file mode 100644 index 00000000..0d34e14d --- /dev/null +++ b/tests/cli/test_debug_info.in @@ -0,0 +1,34 @@ +#!/bin/bash +# +# Copyright (C) - 2017 Julien Desfossez +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License, version 2 only, as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., 51 +# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +CURDIR=$(dirname $0) +TESTDIR=$CURDIR/.. + +BABELTRACE_BIN=@abs_top_builddir@/cli/babeltrace + +BT_TREE_PATH=@abs_top_srcdir@/ +DEBUG_INFO_TRACE=${BT_TREE_PATH}/tests/debug-info-data/trace/ + +source $TESTDIR/utils/tap/tap.sh + +NUM_TESTS=1 + +plan_tests $NUM_TESTS + +$BABELTRACE_BIN --debug-info-target-prefix ${BT_TREE_PATH} ${DEBUG_INFO_TRACE} 2>/dev/null \ + | @GREP@ 'debug_info = { bin = "libhello_so+0x15a6", func = "bar+0xa9", src = "libhello.c:13" }' >/dev/null +ok $? "Extract debug information" diff --git a/tests/debug-info-data/README.md b/tests/debug-info-data/README.md index 6a4c36c3..1c45c505 100644 --- a/tests/debug-info-data/README.md +++ b/tests/debug-info-data/README.md @@ -62,3 +62,20 @@ https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html $ objcopy --only-keep-debug libhello_debug_link_so libhello_debug_link_so.debug $ strip -g libhello_debug_link_so $ objcopy --add-gnu-debuglink=libhello_debug_link_so.debug libhello_debug_link_so + + +Test program +------------ +An executable linked to this library can be compiled from the `main.c` source file. +To compile it, you can do: + + $ ln -s libhello_so libhello.so + $ gcc -I. -o test main.c -L. -lhello_build_id -llttng-ust -ldl -Wl,--rpath=. + +The trace provided in this directory was generated with lttng-ust running this +program and stripped to contain only the bare minimum. When running babeltrace +with the `--debug-info-target-prefix` option pointing to the source tree of +Babeltrace, the `my_provider:my_first_tracepoint` events should contain this +information: + + debug_info = { bin = "libhello_so+0x166b", func = "baz+0x9c", src = "libhello.c:20" } } diff --git a/tests/debug-info-data/main.c b/tests/debug-info-data/main.c new file mode 100644 index 00000000..e272bc10 --- /dev/null +++ b/tests/debug-info-data/main.c @@ -0,0 +1,37 @@ +/* + * main.c + * + * Debug Info - Main + * + * Copyright 2017 Julien Desfossez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "libhello.h" +#include "tp.h" + +int main() +{ + foo(); + bar(); + baz(); + return 0; +} diff --git a/tests/debug-info-data/trace/metadata b/tests/debug-info-data/trace/metadata new file mode 100644 index 00000000..1388b296 --- /dev/null +++ b/tests/debug-info-data/trace/metadata @@ -0,0 +1,91 @@ +/* CTF 1.8 */ + +trace { + major = 1; + minor = 8; + uuid = "c4f5ad74-2d9a-4a17-9633-3e9e49d5f773"; + byte_order = le; + packet.header := struct { + integer { size = 32; align = 8; signed = false; encoding = none; base = decimal; byte_order = le; } magic; + integer { size = 8; align = 8; signed = false; encoding = none; base = decimal; byte_order = le; } uuid[16]; + integer { size = 32; align = 8; signed = false; encoding = none; base = decimal; byte_order = le; } stream_id; + integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = le; } stream_instance_id; + } align(8); +}; + +env { + hostname = "sinkpad"; + domain = "ust"; + tracer_name = "lttng-ust"; + tracer_major = 2; + tracer_minor = 10; +}; + +clock { + name = monotonic; + uuid = "00000000-0000-0000-0000-000000000000"; + description = "Monotonic Clock"; + freq = 1000000000; + precision = 1; + offset_s = 0; + offset = 1497619475540462738; + absolute = TRUE; +}; + +stream { + id = 0; + event.header := struct { + enum : integer { size = 5; align = 1; signed = false; encoding = none; base = decimal; byte_order = le; } { "compact" = 0 ... 30, "extended" = 31 } id; + variant { + struct { + integer { size = 64; align = 1; signed = false; encoding = none; base = decimal; byte_order = le; map = clock.monotonic.value; } timestamp; + } align(1) compact; + struct { + integer { size = 32; align = 8; signed = false; encoding = none; base = decimal; byte_order = le; } id; + integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = le; map = clock.monotonic.value; } timestamp; + } align(8) extended; + } v; + } align(8); + + packet.context := struct { + integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = le; map = clock.monotonic.value; } timestamp_begin; + integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = le; map = clock.monotonic.value; } timestamp_end; + integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = le; } content_size; + integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = le; } packet_size; + integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = le; } packet_seq_num; + integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = le; } events_discarded; + integer { size = 32; align = 8; signed = false; encoding = none; base = decimal; byte_order = le; } cpu_id; + } align(8); + + event.context := struct { + integer { size = 32; align = 8; signed = true; encoding = none; base = decimal; byte_order = le; } _vpid; + integer { size = 64; align = 8; signed = false; encoding = none; base = hexadecimal; byte_order = le; } _ip; + } align(8); +}; + +event { + name = "lttng_ust_statedump:bin_info"; + id = 0; + stream_id = 0; + loglevel = 13; + fields := struct { + integer { size = 64; align = 8; signed = false; encoding = none; base = hexadecimal; byte_order = le; } _baddr; + integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = le; } _memsz; + string { encoding = UTF8; } _path; + integer { size = 8; align = 8; signed = false; encoding = none; base = decimal; byte_order = le; } _is_pic; + integer { size = 8; align = 8; signed = false; encoding = none; base = decimal; byte_order = le; } _has_build_id; + integer { size = 8; align = 8; signed = false; encoding = none; base = decimal; byte_order = le; } _has_debug_link; + } align(8); +}; + +event { + name = "my_provider:my_first_tracepoint"; + id = 1; + stream_id = 0; + loglevel = 13; + fields := struct { + string { encoding = UTF8; } _my_string_field; + integer { size = 32; align = 8; signed = true; encoding = none; base = decimal; byte_order = le; } _my_integer_field; + } align(8); +}; + diff --git a/tests/debug-info-data/trace/stream_0_0 b/tests/debug-info-data/trace/stream_0_0 new file mode 100644 index 0000000000000000000000000000000000000000..582f445a3841e01d97bc4f5dcc31cfc21bf2ab8d GIT binary patch literal 292 zcmX>o|L5S5uWL(mXL*TFGq#)OdG&iS0}@b}w`C2*Q0@c&ED$}zQUR<`za+J|q*y;CHK{aRH#09SUpFPOBvC&n zGbtlACnrC?IG=%$k)h!!HlqS!I{$-=go5a@l;ZqY5XUhj2VwIS76Gu0VDoeoN{SMb sQ;Qh1fXWV9bRm>2V}&RyN=?qs0Xj+{wM3yfH8(LcCnvR-!4jw(04V8B{r~^~ literal 0 HcmV?d00001 -- 2.34.1