Test debug-info
authorJulien Desfossez <jdesfossez@efficios.com>
Fri, 16 Jun 2017 18:30:30 +0000 (14:30 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 19 Jun 2017 15:49:45 +0000 (11:49 -0400)
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 <jdesfossez@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
.gitignore
configure.ac
tests/cli/Makefile.am
tests/cli/test_debug_info.in [new file with mode: 0644]
tests/debug-info-data/README.md
tests/debug-info-data/main.c [new file with mode: 0644]
tests/debug-info-data/trace/metadata [new file with mode: 0644]
tests/debug-info-data/trace/stream_0_0 [new file with mode: 0644]

index d7a49b12e379f7bfe002fd0415450b00ce5efd54..f738622ddb3def09173220c35cbb97007bd04d8f 100644 (file)
@@ -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
index 323afa75e49b25c9c5995ac96d4007301ed0adda..bdfe76ac0dc30d3777a1c69b68a4a6c076d51e35 100644 (file)
@@ -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])
index 27e67dfae58422b2c2d29f6b66f41c8a84ca0429..d4437659f922a83b6ee142f4e1a5aa766aeac260 100644 (file)
@@ -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 (file)
index 0000000..0d34e14
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/bash
+#
+# Copyright (C) - 2017 Julien Desfossez <jdesfossez@efficios.com>
+#
+# 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"
index 6a4c36c301b20dc0caf951d1ce1bb02e60a2f838..1c45c505436514dd5f341eebd5a3e6a9e459e986 100644 (file)
@@ -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 (file)
index 0000000..e272bc1
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * main.c
+ *
+ * Debug Info - Main
+ *
+ * Copyright 2017 Julien Desfossez <jdesfossez@efficios.com>
+ *
+ * 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 <stdio.h>
+#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 (file)
index 0000000..1388b29
--- /dev/null
@@ -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 <id> {
+                       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 (file)
index 0000000..582f445
Binary files /dev/null and b/tests/debug-info-data/trace/stream_0_0 differ
This page took 0.029167 seconds and 4 git commands to generate.