/usr/src/gcc-4.7/debian/patches/ada-symbolic-tracebacks.diff is in gcc-4.7-source 4.7.3-12ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | # DP: - Enable support for symbolic tracebacks in exceptions (delete the dummy
# DP: convert_addresses from adaint.c, and provide a real one separately.)
Ported Jürgen Pfeifer's patch to enable symbolic tracebacks on Debian
GNU/Linux.
The binary distribution of GNAT 3.15p comes with an old version of
binutils that includes a library, libaddr2line.a. This library does
not exist in recent versions of binutils. The patch works around this
by calling /usr/bin/addr2line (still part of binutils) and parsing the
output. See debian/convert_addresses.c for the gory details.
I have modified convert_addresses.c to not use a shell script anymore;
Debian controls the version of binutils which is installed. Also, I
use execve instead of execle.
--
Ludovic Brenta.
# ' make emacs highlighting happy
Index: b/src/gcc/ada/gcc-interface/Makefile.in
===================================================================
--- a/src/gcc/ada/gcc-interface/Makefile.in
+++ b/src/gcc/ada/gcc-interface/Makefile.in
@@ -247,8 +247,8 @@
# Both . and srcdir are used, in that order,
# so that tm.h and config.h will be found in the compilation
# subdirectory rather than in the source directory.
-INCLUDES = -I- -I. -I.. -I$(srcdir)/ada -I$(srcdir) -I$(srcdir)/config \
- -I$(srcdir)/../include
+INCLUDES = -iquote . -iquote .. -iquote $(srcdir)/ada -iquote$(srcdir) \
+ -iquote $(srcdir)/config -iquote $(srcdir)/../include
ADA_INCLUDES = -I- -I. -I$(srcdir)/ada
@@ -2235,7 +2235,7 @@
a-nucoar.o a-nurear.o i-forbla.o i-forlap.o s-gearop.o
GNATRTL_OBJS = $(GNATRTL_NONTASKING_OBJS) $(GNATRTL_TASKING_OBJS) \
- $(GNATRTL_LINEARALGEBRA_OBJS) g-trasym.o memtrack.o
+ $(GNATRTL_LINEARALGEBRA_OBJS) g-trasym.o memtrack.o convert_addresses.o
# Default run time files
@@ -2358,7 +2358,6 @@
for file in $(RTSDIR)/*.ali; do \
$(INSTALL_DATA_DATE) $$file $(DESTDIR)$(ADA_RTL_OBJ_DIR); \
done
- -$(INSTALL_DATA) $(RTSDIR)/g-trasym$(objext) $(DESTDIR)$(ADA_RTL_OBJ_DIR)
-cd $(RTSDIR); for file in *$(arext);do \
$(INSTALL_DATA) $$file $(DESTDIR)$(ADA_RTL_OBJ_DIR); \
$(RANLIB_FOR_TARGET) $(DESTDIR)$(ADA_RTL_OBJ_DIR)/$$file; \
@@ -2469,7 +2468,7 @@
$(GNATRTL_OBJS)
$(RM) $(RTSDIR)/libgnat$(arext) $(RTSDIR)/libgnarl$(arext)
$(AR_FOR_TARGET) $(AR_FLAGS) $(RTSDIR)/libgnat$(arext) \
- $(addprefix $(RTSDIR)/,$(GNATRTL_NONTASKING_OBJS) $(LIBGNAT_OBJS))
+ $(addprefix $(RTSDIR)/,$(GNATRTL_NONTASKING_OBJS) $(LIBGNAT_OBJS) g-trasym.o convert_addresses.o)
$(RANLIB_FOR_TARGET) $(RTSDIR)/libgnat$(arext)
$(AR_FOR_TARGET) $(AR_FLAGS) $(RTSDIR)/libgnarl$(arext) \
$(addprefix $(RTSDIR)/,$(GNATRTL_TASKING_OBJS))
@@ -2499,6 +2498,7 @@
$(TARGET_LIBGCC2_CFLAGS) \
-o libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) \
$(GNATRTL_NONTASKING_OBJS) $(LIBGNAT_OBJS) \
+ g-trasym.o convert_addresses.o \
$(SO_OPTS)libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) \
$(MISCLIB) -lm
cd $(RTSDIR); ../../xgcc -B../../ -shared $(GNATLIBCFLAGS) \
@@ -2761,6 +2761,7 @@
sysdep.o : sysdep.c
raise-gcc.o : raise-gcc.c raise.h
raise.o : raise.c raise.h
+convert_addresses.o : convert_addresses.c
vx_stack_info.o : vx_stack_info.c
cio.o : cio.c
Index: b/src/gcc/ada/adaint.c
===================================================================
--- a/src/gcc/ada/adaint.c
+++ b/src/gcc/ada/adaint.c
@@ -3421,37 +3421,6 @@
}
#endif
-#if defined (IS_CROSS) \
- || (! ((defined (sparc) || defined (i386)) && defined (sun) \
- && defined (__SVR4)) \
- && ! (defined (linux) && (defined (i386) || defined (__x86_64__))) \
- && ! (defined (linux) && defined (__ia64__)) \
- && ! (defined (linux) && defined (powerpc)) \
- && ! defined (__FreeBSD__) \
- && ! defined (__Lynx__) \
- && ! defined (__hpux__) \
- && ! defined (__APPLE__) \
- && ! defined (_AIX) \
- && ! (defined (__alpha__) && defined (__osf__)) \
- && ! defined (VMS) \
- && ! defined (__MINGW32__) \
- && ! (defined (__mips) && defined (__sgi)))
-
-/* Dummy function to satisfy g-trasym.o. See the preprocessor conditional
- just above for a list of native platforms that provide a non-dummy
- version of this procedure in libaddr2line.a. */
-
-void
-convert_addresses (const char *file_name ATTRIBUTE_UNUSED,
- void *addrs ATTRIBUTE_UNUSED,
- int n_addr ATTRIBUTE_UNUSED,
- void *buf ATTRIBUTE_UNUSED,
- int *len ATTRIBUTE_UNUSED)
-{
- *len = 0;
-}
-#endif
-
#if defined (_WIN32)
int __gnat_argument_needs_quote = 1;
#else
Index: b/src/gcc/ada/convert_addresses.c
===================================================================
--- /dev/null
+++ b/src/gcc/ada/convert_addresses.c
@@ -0,0 +1,154 @@
+/*
+ Copyright (C) 1999 by Juergen Pfeifer <juergen.pfeifer@gmx.net>
+ Ada for Linux Team (ALT)
+
+ 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, distribute with modifications, 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 ABOVE 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.
+
+ Except as contained in this notice, the name(s) of the above copyright
+ holders shall not be used in advertising or otherwise to promote the
+ sale, use or other dealings in this Software without prior written
+ authorization.
+*/
+#include <sys/types.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <signal.h>
+
+#define STDIN_FILENO 0
+#define STDOUT_FILENO 1
+#define MAX_LINE 1024
+
+#define CLOSE1 close(fd1[0]); close(fd1[1])
+#define CLOSE2 close(fd2[0]); close(fd2[1])
+#define RESTSIG sigaction(SIGPIPE,&oact,NULL)
+
+void convert_addresses
+(const char *file_name,
+ void* addrs[],
+ int n_addr,
+ char* buf,
+ int* len)
+{
+ int max_len = *len;
+ pid_t pid = getpid();
+ pid_t child;
+
+ struct sigaction act, oact;
+
+ int fd1[2], fd2[2];
+
+ *buf = 0; *len = 0;
+ act.sa_handler = SIG_IGN;
+ sigemptyset(&act.sa_mask);
+ act.sa_flags = 0;
+ if (sigaction(SIGPIPE,&act,&oact) < 0)
+ return;
+
+ if (pipe(fd1) >= 0) {
+ if (pipe(fd2)>=0) {
+ if ((child = fork()) < 0) {
+ CLOSE1; CLOSE2; RESTSIG;
+ return;
+ }
+ else {
+ if (0==child) {
+ close(fd1[1]);
+ close(fd2[0]);
+ if (fd1[0] != STDIN_FILENO) {
+ if (dup2(fd1[0],STDIN_FILENO) != STDIN_FILENO) {
+ CLOSE1; CLOSE2;
+ }
+ close(fd1[0]);
+ }
+ if (fd2[1] != STDOUT_FILENO) {
+ if (dup2(fd2[1],STDOUT_FILENO) != STDOUT_FILENO) {
+ CLOSE1; CLOSE2;
+ }
+ close(fd2[1]);
+ }
+ {
+ /* As pointed out by Florian Weimer to me, it is a
+ security threat to call the script with a user defined
+ environment and using the path. That would be Trojans
+ pleasure. Therefore we use the absolute path to
+ addr2line and an empty environment. That should be
+ safe.
+ */
+ char *const argv[] = { "addr2line",
+ "-e",
+ file_name,
+ "--demangle=gnat",
+ "--functions",
+ "--basenames",
+ NULL };
+ char *const envp[] = { NULL };
+ if (execve("/usr/bin/addr2line", argv, envp) < 0) {
+ CLOSE1; CLOSE2;
+ }
+ }
+ }
+ else {
+ int i, n;
+ char hex[16];
+ char line[MAX_LINE + 1];
+ char *p;
+ char *s = buf;
+
+ /* Parent context */
+ close(fd1[0]);
+ close(fd2[1]);
+
+ for(i=0; i < n_addr; i++) {
+ snprintf(hex,sizeof(hex),"%p\n",addrs[i]);
+ write(fd1[1],hex,strlen(hex));
+ n = read(fd2[0],line,MAX_LINE);
+ if (n<=0)
+ break;
+ line[n]=0;
+ /* We have approx. 16 additional chars for "%p in " clause.
+ We use this info to prevent a buffer overrun.
+ */
+ if (n + 16 + (*len) > max_len)
+ break;
+ p = strchr(line,'\n');
+ if (p) {
+ if (*(p+1)) {
+ *p = 0;
+ *len += snprintf(s, (max_len - (*len)), "%p in %s at %s",addrs[i], line, p+1);
+ }
+ else {
+ *len += snprintf(s, (max_len - (*len)), "%p at %s",addrs[i], line);
+ }
+ s = buf + (*len);
+ }
+ }
+ close(fd1[1]);
+ close(fd2[0]);
+ }
+ }
+ }
+ else {
+ CLOSE1;
+ }
+ }
+ RESTSIG;
+}
Index: b/src/gcc/ada/g-trasym.adb
===================================================================
--- a/src/gcc/ada/g-trasym.adb
+++ b/src/gcc/ada/g-trasym.adb
@@ -32,16 +32,16 @@
------------------------------------------------------------------------------
-- Run-time symbolic traceback support
+-- This file has been modified by Juergen Pfeifer (31-Dec-1999) for
+-- the purpose to support the Ada for Linux Team implementation of
+-- convert_addresses. This implementation has the advantage to run
+-- on the binutils as they are deployed on Linux.
with System.Soft_Links;
with Ada.Exceptions.Traceback; use Ada.Exceptions.Traceback;
package body GNAT.Traceback.Symbolic is
- pragma Linker_Options ("-laddr2line");
- pragma Linker_Options ("-lbfd");
- pragma Linker_Options ("-liberty");
-
package TSL renames System.Soft_Links;
-- To perform the raw addresses to symbolic form translation we rely on a
@@ -80,10 +80,6 @@
-- FILENAME. LEN points to an integer which contains the size of the
-- BUF buffer at input and the result length at output.
--
- -- This procedure is provided by libaddr2line on targets that support
- -- it. A dummy version is in adaint.c for other targets so that build
- -- of shared libraries doesn't generate unresolved symbols.
- --
-- Note that this procedure is *not* thread-safe.
type Argv_Array is array (0 .. 0) of System.Address;
@@ -94,8 +90,9 @@
(c_exename : System.Address) return System.Address;
pragma Import (C, locate_exec_on_path, "__gnat_locate_exec_on_path");
- Res : String (1 .. 256 * Traceback'Length);
- Len : Integer;
+ B_Size : constant Integer := 256 * Traceback'Length;
+ Len : Integer := B_Size;
+ Res : String (1 .. B_Size);
use type System.Address;
|