|
|
7b26da |
commit 1b5d0ab34c53d6e896d2c0958b1176e324bb7878
|
|
|
7b26da |
Author: Pedro Alves <palves@redhat.com>
|
|
|
7b26da |
Date: Wed Jul 16 19:25:41 2014 +0100
|
|
|
7b26da |
|
|
|
7b26da |
gdb.trace/tfile.c: Remove Thumb bit in one more more, general cleanup
|
|
|
7b26da |
|
|
|
7b26da |
I noticed that the existing code casts a function's address to 'long',
|
|
|
7b26da |
but that doesn't work correctly on some ABIs, like Win64, where long
|
|
|
7b26da |
is 32-bit and while pointers are 64-bit:
|
|
|
7b26da |
|
|
|
7b26da |
func_addr = (long) &write_basic_trace_file;
|
|
|
7b26da |
|
|
|
7b26da |
Fixing that showed there's actually another place in the file that
|
|
|
7b26da |
writes a function address to file, and therefore should clear the
|
|
|
7b26da |
Thumb bit. This commit adds a macro+function pair to centralize the
|
|
|
7b26da |
Thumb bit handling, and uses it in both places.
|
|
|
7b26da |
|
|
|
7b26da |
The rest is just enough changes to make the file build without
|
|
|
7b26da |
warnings with "-Wall -Wextra" with x86_64-w64-mingw32-gcc and
|
|
|
7b26da |
i686-w64-mingw32-gcc cross compilers, and with -m32/-m64 on x86_64
|
|
|
7b26da |
GNU/Linux. Currently with x86_64-w64-mingw32-gcc we get:
|
|
|
7b26da |
|
|
|
7b26da |
$ x86_64-w64-mingw32-gcc tfile.c -Wall -DTFILE_DIR=\"\"
|
|
|
7b26da |
tfile.c: In function 'start_trace_file':
|
|
|
7b26da |
tfile.c:51:23: error: 'S_IRGRP' undeclared (first use in this function)
|
|
|
7b26da |
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
|
|
|
7b26da |
^
|
|
|
7b26da |
tfile.c:51:23: note: each undeclared identifier is reported only once for each function it appears in
|
|
|
7b26da |
tfile.c:51:31: error: 'S_IROTH' undeclared (first use in this function)
|
|
|
7b26da |
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
|
|
|
7b26da |
^
|
|
|
7b26da |
tfile.c: In function 'add_memory_block':
|
|
|
7b26da |
tfile.c:79:10: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
|
|
|
7b26da |
ll_x = (unsigned long) addr;
|
|
|
7b26da |
^
|
|
|
7b26da |
tfile.c: In function 'write_basic_trace_file':
|
|
|
7b26da |
tfile.c:113:15: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
|
|
|
7b26da |
func_addr = (long) &write_basic_trace_file;
|
|
|
7b26da |
^
|
|
|
7b26da |
tfile.c:137:3: warning: passing argument 1 of 'add_memory_block' from incompatible pointer type [enabled by default]
|
|
|
7b26da |
add_memory_block (&testglob, sizeof (testglob));
|
|
|
7b26da |
^
|
|
|
7b26da |
tfile.c:72:1: note: expected 'char *' but argument is of type 'int *'
|
|
|
7b26da |
add_memory_block (char *addr, int size)
|
|
|
7b26da |
^
|
|
|
7b26da |
tfile.c:139:3: warning: passing argument 1 of 'add_memory_block' from incompatible pointer type [enabled by default]
|
|
|
7b26da |
add_memory_block (&testglob2, 1);
|
|
|
7b26da |
^
|
|
|
7b26da |
tfile.c:72:1: note: expected 'char *' but argument is of type 'int *'
|
|
|
7b26da |
add_memory_block (char *addr, int size)
|
|
|
7b26da |
^
|
|
|
7b26da |
tfile.c: In function 'write_error_trace_file':
|
|
|
7b26da |
tfile.c:185:3: warning: implicit declaration of function 'alloca' [-Wimplicit-function-declaration]
|
|
|
7b26da |
char *hex = alloca (len * 2 + 1);
|
|
|
7b26da |
^
|
|
|
7b26da |
tfile.c:185:15: warning: incompatible implicit declaration of built-in function 'alloca' [enabled by default]
|
|
|
7b26da |
char *hex = alloca (len * 2 + 1);
|
|
|
7b26da |
^
|
|
|
7b26da |
tfile.c:211:6: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
|
|
|
7b26da |
(long) &write_basic_trace_file);
|
|
|
7b26da |
^
|
|
|
7b26da |
|
|
|
7b26da |
Tested on x86_64 Fedora 20, -m64 and -m32.
|
|
|
7b26da |
Tested by Yao on arm targets.
|
|
|
7b26da |
|
|
|
7b26da |
gdb/testsuite/
|
|
|
7b26da |
2014-07-16 Pedro Alves <palves@redhat.com>
|
|
|
7b26da |
|
|
|
7b26da |
* gdb.trace/tfile.c: Include unistd.h and stdint.h.
|
|
|
7b26da |
(start_trace_file): Guard S_IRGRP and S_IROTH uses behind #ifdef.
|
|
|
7b26da |
(tfile_write_64, tfile_write_16, tfile_write_8, tfile_write_addr)
|
|
|
7b26da |
(tfile_write_buf): New functions.
|
|
|
7b26da |
(add_memory_block): Rewrite using the above.
|
|
|
7b26da |
(adjust_function_address): New function.
|
|
|
7b26da |
(FUNCTION_ADDRESS): New macro.
|
|
|
7b26da |
(write_basic_trace_file): Remove short_x local, and use
|
|
|
7b26da |
tfile_write_16. Change type of func_addr local to unsigned long
|
|
|
7b26da |
long. Use FUNCTION_ADDRESS instead of handling the Thumb bit
|
|
|
7b26da |
here. Cast argument of add_memory_block to char pointer.
|
|
|
7b26da |
(write_error_trace_file): Avoid alloca. Use FUNCTION_ADDRESS.
|
|
|
7b26da |
(main): Remove parameters.
|
|
|
7b26da |
* gdb.trace/tfile.exp: Remove nowarnings.
|
|
|
7b26da |
|
|
|
7b26da |
Index: gdb-7.6.1/gdb/testsuite/gdb.trace/tfile.c
|
|
|
7b26da |
===================================================================
|
|
|
7b26da |
--- gdb-7.6.1.orig/gdb/testsuite/gdb.trace/tfile.c
|
|
|
7b26da |
+++ gdb-7.6.1/gdb/testsuite/gdb.trace/tfile.c
|
|
|
7b26da |
@@ -3,9 +3,11 @@
|
|
|
7b26da |
GDB. */
|
|
|
7b26da |
|
|
|
7b26da |
#include <stdio.h>
|
|
|
7b26da |
+#include <unistd.h>
|
|
|
7b26da |
#include <string.h>
|
|
|
7b26da |
#include <fcntl.h>
|
|
|
7b26da |
#include <sys/stat.h>
|
|
|
7b26da |
+#include <stdint.h>
|
|
|
7b26da |
|
|
|
7b26da |
char spbuf[200];
|
|
|
7b26da |
|
|
|
7b26da |
@@ -23,9 +25,17 @@ int
|
|
|
7b26da |
start_trace_file (char *filename)
|
|
|
7b26da |
{
|
|
|
7b26da |
int fd;
|
|
|
7b26da |
+ mode_t mode = S_IRUSR | S_IWUSR;
|
|
|
7b26da |
|
|
|
7b26da |
- fd = open (filename, O_WRONLY|O_CREAT|O_APPEND,
|
|
|
7b26da |
- S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
|
|
|
7b26da |
+#ifdef S_IRGRP
|
|
|
7b26da |
+ mode |= S_IRGRP;
|
|
|
7b26da |
+#endif
|
|
|
7b26da |
+
|
|
|
7b26da |
+#ifdef S_IROTH
|
|
|
7b26da |
+ mode |= S_IROTH;
|
|
|
7b26da |
+#endif
|
|
|
7b26da |
+
|
|
|
7b26da |
+ fd = open (filename, O_WRONLY|O_CREAT|O_APPEND, mode);
|
|
|
7b26da |
|
|
|
7b26da |
if (fd < 0)
|
|
|
7b26da |
return fd;
|
|
|
7b26da |
@@ -44,31 +54,73 @@ finish_trace_file (int fd)
|
|
|
7b26da |
close (fd);
|
|
|
7b26da |
}
|
|
|
7b26da |
|
|
|
7b26da |
+static void
|
|
|
7b26da |
+tfile_write_64 (uint64_t value)
|
|
|
7b26da |
+{
|
|
|
7b26da |
+ memcpy (trptr, &value, sizeof (uint64_t));
|
|
|
7b26da |
+ trptr += sizeof (uint64_t);
|
|
|
7b26da |
+}
|
|
|
7b26da |
|
|
|
7b26da |
-void
|
|
|
7b26da |
-add_memory_block (char *addr, int size)
|
|
|
7b26da |
+static void
|
|
|
7b26da |
+tfile_write_16 (uint16_t value)
|
|
|
7b26da |
+{
|
|
|
7b26da |
+ memcpy (trptr, &value, sizeof (uint16_t));
|
|
|
7b26da |
+ trptr += sizeof (uint16_t);
|
|
|
7b26da |
+}
|
|
|
7b26da |
+
|
|
|
7b26da |
+static void
|
|
|
7b26da |
+tfile_write_8 (uint8_t value)
|
|
|
7b26da |
{
|
|
|
7b26da |
- short short_x;
|
|
|
7b26da |
- unsigned long long ll_x;
|
|
|
7b26da |
+ memcpy (trptr, &value, sizeof (uint8_t));
|
|
|
7b26da |
+ trptr += sizeof (uint8_t);
|
|
|
7b26da |
+}
|
|
|
7b26da |
|
|
|
7b26da |
- *((char *) trptr) = 'M';
|
|
|
7b26da |
- trptr += 1;
|
|
|
7b26da |
- ll_x = (unsigned long) addr;
|
|
|
7b26da |
- memcpy (trptr, &ll_x, sizeof (unsigned long long));
|
|
|
7b26da |
- trptr += sizeof (unsigned long long);
|
|
|
7b26da |
- short_x = size;
|
|
|
7b26da |
- memcpy (trptr, &short_x, 2);
|
|
|
7b26da |
- trptr += 2;
|
|
|
7b26da |
+static void
|
|
|
7b26da |
+tfile_write_addr (char *addr)
|
|
|
7b26da |
+{
|
|
|
7b26da |
+ tfile_write_64 ((uint64_t) (uintptr_t) addr);
|
|
|
7b26da |
+}
|
|
|
7b26da |
+
|
|
|
7b26da |
+static void
|
|
|
7b26da |
+tfile_write_buf (const void *addr, size_t size)
|
|
|
7b26da |
+{
|
|
|
7b26da |
memcpy (trptr, addr, size);
|
|
|
7b26da |
trptr += size;
|
|
|
7b26da |
}
|
|
|
7b26da |
|
|
|
7b26da |
void
|
|
|
7b26da |
+add_memory_block (char *addr, int size)
|
|
|
7b26da |
+{
|
|
|
7b26da |
+ tfile_write_8 ('M');
|
|
|
7b26da |
+ tfile_write_addr (addr);
|
|
|
7b26da |
+ tfile_write_16 (size);
|
|
|
7b26da |
+ tfile_write_buf (addr, size);
|
|
|
7b26da |
+}
|
|
|
7b26da |
+
|
|
|
7b26da |
+/* Adjust a function's address to account for architectural
|
|
|
7b26da |
+ particularities. */
|
|
|
7b26da |
+
|
|
|
7b26da |
+static uintptr_t
|
|
|
7b26da |
+adjust_function_address (uintptr_t func_addr)
|
|
|
7b26da |
+{
|
|
|
7b26da |
+#if defined(__thumb__) || defined(__thumb2__)
|
|
|
7b26da |
+ /* Although Thumb functions are two-byte aligned, function
|
|
|
7b26da |
+ pointers have the Thumb bit set. Clear it. */
|
|
|
7b26da |
+ return func_addr & ~1;
|
|
|
7b26da |
+#else
|
|
|
7b26da |
+ return func_addr;
|
|
|
7b26da |
+#endif
|
|
|
7b26da |
+}
|
|
|
7b26da |
+
|
|
|
7b26da |
+/* Get a function's address as an integer. */
|
|
|
7b26da |
+
|
|
|
7b26da |
+#define FUNCTION_ADDRESS(FUN) adjust_function_address ((uintptr_t) &FUN)
|
|
|
7b26da |
+
|
|
|
7b26da |
+void
|
|
|
7b26da |
write_basic_trace_file (void)
|
|
|
7b26da |
{
|
|
|
7b26da |
int fd, int_x;
|
|
|
7b26da |
- short short_x;
|
|
|
7b26da |
- long func_addr;
|
|
|
7b26da |
+ unsigned long long func_addr;
|
|
|
7b26da |
|
|
|
7b26da |
fd = start_trace_file ("basic.tf");
|
|
|
7b26da |
|
|
|
7b26da |
@@ -86,15 +138,9 @@ write_basic_trace_file (void)
|
|
|
7b26da |
|
|
|
7b26da |
/* Dump tracepoint definitions, in syntax similar to that used
|
|
|
7b26da |
for reconnection uploads. */
|
|
|
7b26da |
- /* FIXME need a portable way to print function address in hex */
|
|
|
7b26da |
- func_addr = (long) &write_basic_trace_file;
|
|
|
7b26da |
-#if defined(__thumb__) || defined(__thumb2__)
|
|
|
7b26da |
- /* Although Thumb functions are two-byte aligned, function
|
|
|
7b26da |
- pointers have the Thumb bit set. Clear it. */
|
|
|
7b26da |
- func_addr &= ~1;
|
|
|
7b26da |
-#endif
|
|
|
7b26da |
+ func_addr = FUNCTION_ADDRESS (write_basic_trace_file);
|
|
|
7b26da |
|
|
|
7b26da |
- snprintf (spbuf, sizeof spbuf, "tp T1:%lx:E:0:0\n", func_addr);
|
|
|
7b26da |
+ snprintf (spbuf, sizeof spbuf, "tp T1:%llx:E:0:0\n", func_addr);
|
|
|
7b26da |
write (fd, spbuf, strlen (spbuf));
|
|
|
7b26da |
/* (Note that we would only need actions defined if we wanted to
|
|
|
7b26da |
test tdump.) */
|
|
|
7b26da |
@@ -106,14 +152,13 @@ write_basic_trace_file (void)
|
|
|
7b26da |
/* (Encapsulate better if we're going to do lots of this; note that
|
|
|
7b26da |
buffer endianness is the target program's enddianness.) */
|
|
|
7b26da |
trptr = trbuf;
|
|
|
7b26da |
- short_x = 1;
|
|
|
7b26da |
- memcpy (trptr, &short_x, 2);
|
|
|
7b26da |
- trptr += 2;
|
|
|
7b26da |
+ tfile_write_16 (1);
|
|
|
7b26da |
+
|
|
|
7b26da |
tfsizeptr = trptr;
|
|
|
7b26da |
trptr += 4;
|
|
|
7b26da |
- add_memory_block (&testglob, sizeof (testglob));
|
|
|
7b26da |
+ add_memory_block ((char *) &testglob, sizeof (testglob));
|
|
|
7b26da |
/* Divide a variable between two separate memory blocks. */
|
|
|
7b26da |
- add_memory_block (&testglob2, 1);
|
|
|
7b26da |
+ add_memory_block ((char *) &testglob2, 1);
|
|
|
7b26da |
add_memory_block (((char*) &testglob2) + 1, sizeof (testglob2) - 1);
|
|
|
7b26da |
/* Go back and patch in the frame size. */
|
|
|
7b26da |
int_x = trptr - tfsizeptr - sizeof (int);
|
|
|
7b26da |
@@ -158,8 +203,8 @@ write_error_trace_file (void)
|
|
|
7b26da |
{
|
|
|
7b26da |
int fd;
|
|
|
7b26da |
const char made_up[] = "made-up error";
|
|
|
7b26da |
+ char hex[(sizeof (made_up) - 1) * 2 + 1];
|
|
|
7b26da |
int len = sizeof (made_up) - 1;
|
|
|
7b26da |
- char *hex = alloca (len * 2 + 1);
|
|
|
7b26da |
|
|
|
7b26da |
fd = start_trace_file ("error.tf");
|
|
|
7b26da |
|
|
|
7b26da |
@@ -183,9 +228,8 @@ write_error_trace_file (void)
|
|
|
7b26da |
|
|
|
7b26da |
/* Dump tracepoint definitions, in syntax similar to that used
|
|
|
7b26da |
for reconnection uploads. */
|
|
|
7b26da |
- /* FIXME need a portable way to print function address in hex */
|
|
|
7b26da |
- snprintf (spbuf, sizeof spbuf, "tp T1:%lx:E:0:0\n",
|
|
|
7b26da |
- (long) &write_basic_trace_file);
|
|
|
7b26da |
+ snprintf (spbuf, sizeof spbuf, "tp T1:%llx:E:0:0\n",
|
|
|
7b26da |
+ (unsigned long long) FUNCTION_ADDRESS (write_basic_trace_file));
|
|
|
7b26da |
write (fd, spbuf, strlen (spbuf));
|
|
|
7b26da |
/* (Note that we would only need actions defined if we wanted to
|
|
|
7b26da |
test tdump.) */
|
|
|
7b26da |
@@ -210,7 +254,7 @@ done_making_trace_files (void)
|
|
|
7b26da |
}
|
|
|
7b26da |
|
|
|
7b26da |
int
|
|
|
7b26da |
-main (int argc, char **argv, char **envp)
|
|
|
7b26da |
+main (void)
|
|
|
7b26da |
{
|
|
|
7b26da |
write_basic_trace_file ();
|
|
|
7b26da |
|
|
|
7b26da |
Index: gdb-7.6.1/gdb/testsuite/gdb.trace/tfile.exp
|
|
|
7b26da |
===================================================================
|
|
|
7b26da |
--- gdb-7.6.1.orig/gdb/testsuite/gdb.trace/tfile.exp
|
|
|
7b26da |
+++ gdb-7.6.1/gdb/testsuite/gdb.trace/tfile.exp
|
|
|
7b26da |
@@ -26,7 +26,7 @@ gdb_exit
|
|
|
7b26da |
gdb_start
|
|
|
7b26da |
standard_testfile
|
|
|
7b26da |
if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
|
|
|
7b26da |
- executable {debug nowarnings}] != "" } {
|
|
|
7b26da |
+ executable {debug}] != "" } {
|
|
|
7b26da |
untested ${testfile}.exp
|
|
|
7b26da |
return -1
|
|
|
7b26da |
}
|