]> git.pld-linux.org Git - packages/gdb.git/blame - gdb-minidebuginfo.patch
- typo
[packages/gdb.git] / gdb-minidebuginfo.patch
CommitLineData
a7de96f0
PS
1http://fedoraproject.org/wiki/Features/MiniDebugInfo
2https://bugzilla.redhat.com/show_bug.cgi?id=834068
3
4Patch by Alexander Larsson.
5Review/modifications and testfile by Jan Kratochvil.
6
7Index: gdb-7.4.91.20120801/gdb/Makefile.in
8===================================================================
9--- gdb-7.4.91.20120801.orig/gdb/Makefile.in 2012-08-01 18:44:51.000000000 +0200
10+++ gdb-7.4.91.20120801/gdb/Makefile.in 2012-08-01 18:47:05.701820594 +0200
11@@ -151,6 +151,9 @@ READLINE_CFLAGS = @READLINE_CFLAGS@
12 # Where is expat? This will be empty if expat was not available.
13 LIBEXPAT = @LIBEXPAT@
14
15+# Where is lzma? This will be empty if lzma was not available.
16+LIBLZMA = @LIBLZMA@
17+
18 WARN_CFLAGS = @WARN_CFLAGS@
19 WERROR_CFLAGS = @WERROR_CFLAGS@
20 GDB_WARN_CFLAGS = $(WARN_CFLAGS)
21@@ -467,7 +470,7 @@ INTERNAL_LDFLAGS = $(CFLAGS) $(GLOBAL_CF
22 # LIBIBERTY appears twice on purpose.
23 CLIBS = $(SIM) $(READLINE) $(OPCODES) $(BFD) $(INTL) $(LIBIBERTY) $(LIBDECNUMBER) \
24 $(XM_CLIBS) $(NAT_CLIBS) $(GDBTKLIBS) @LIBS@ @PYTHON_LIBS@ \
25- $(LIBEXPAT) \
26+ $(LIBEXPAT) $(LIBLZMA) \
27 $(LIBIBERTY) $(WIN32LIBS) $(LIBGNU)
28 CDEPS = $(XM_CDEPS) $(NAT_CDEPS) $(SIM) $(BFD) $(READLINE_DEPS) \
29 $(OPCODES) $(INTL_DEPS) $(LIBIBERTY) $(CONFIG_DEPS) $(LIBGNU)
30Index: gdb-7.4.91.20120801/gdb/config.in
31===================================================================
32--- gdb-7.4.91.20120801.orig/gdb/config.in 2012-08-01 18:45:21.000000000 +0200
33+++ gdb-7.4.91.20120801/gdb/config.in 2012-08-01 18:47:05.701820594 +0200
34@@ -198,6 +198,9 @@
35 /* Define to 1 if you have the `libiconvlist' function. */
36 #undef HAVE_LIBICONVLIST
37
38+/* Define if you have the lzma library. */
39+#undef HAVE_LIBLZMA
40+
41 /* Define to 1 if you have the `m' library (-lm). */
42 #undef HAVE_LIBM
43
44Index: gdb-7.4.91.20120801/gdb/configure
45===================================================================
46--- gdb-7.4.91.20120801.orig/gdb/configure 2012-08-01 18:45:21.000000000 +0200
47+++ gdb-7.4.91.20120801/gdb/configure 2012-08-01 18:47:05.703820583 +0200
48@@ -641,6 +641,9 @@ TCL_VERSION
49 WIN32LDAPP
50 GUI_CFLAGS_X
51 LIBGUI
52+LTLIBLZMA
53+LIBLZMA
54+HAVE_LIBLZMA
55 WIN32LIBS
56 SER_HARDWIRE
57 WERROR_CFLAGS
58@@ -813,6 +816,8 @@ with_system_gdbinit
59 enable_werror
60 enable_build_warnings
61 enable_gdb_build_warnings
62+with_lzma
63+with_liblzma_prefix
64 with_tcl
65 with_tk
66 with_x
67@@ -1532,6 +1537,9 @@ Optional Packages:
68 --with-sysroot[=DIR] search for usr/lib et al within DIR
69 --with-system-gdbinit=PATH
70 automatically load a system-wide gdbinit file
71+ --with-lzma support lzma compression (auto/yes/no)
72+ --with-liblzma-prefix[=DIR] search for liblzma in DIR/include and DIR/lib
73+ --without-liblzma-prefix don't search for liblzma in includedir and libdir
74 --with-tcl directory containing tcl configuration (tclConfig.sh)
75 --with-tk directory containing tk configuration (tkConfig.sh)
76 --with-x use the X Window System
77@@ -13151,6 +13159,494 @@ LIBS=$OLD_LIBS
78 # Add any host-specific objects to GDB.
79 CONFIG_OBS="${CONFIG_OBS} ${gdb_host_obs}"
80
81+# If building on ELF, look for lzma support for embedded compressed debug info.
82+if test $gdb_cv_var_elf = yes; then
83+
84+# Check whether --with-lzma was given.
85+if test "${with_lzma+set}" = set; then :
86+ withval=$with_lzma;
87+else
88+ with_lzma=auto
89+fi
90+
91+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to use lzma" >&5
92+$as_echo_n "checking whether to use lzma... " >&6; }
93+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_lzma" >&5
94+$as_echo "$with_lzma" >&6; }
95+
96+ if test "${with_lzma}" != no; then
97+
98+
99+
100+
101+
102+
103+
104+
105+ use_additional=yes
106+
107+ acl_save_prefix="$prefix"
108+ prefix="$acl_final_prefix"
109+ acl_save_exec_prefix="$exec_prefix"
110+ exec_prefix="$acl_final_exec_prefix"
111+
112+ eval additional_includedir=\"$includedir\"
113+ eval additional_libdir=\"$libdir\"
114+
115+ exec_prefix="$acl_save_exec_prefix"
116+ prefix="$acl_save_prefix"
117+
118+
119+# Check whether --with-liblzma-prefix was given.
120+if test "${with_liblzma_prefix+set}" = set; then :
121+ withval=$with_liblzma_prefix;
122+ if test "X$withval" = "Xno"; then
123+ use_additional=no
124+ else
125+ if test "X$withval" = "X"; then
126+
127+ acl_save_prefix="$prefix"
128+ prefix="$acl_final_prefix"
129+ acl_save_exec_prefix="$exec_prefix"
130+ exec_prefix="$acl_final_exec_prefix"
131+
132+ eval additional_includedir=\"$includedir\"
133+ eval additional_libdir=\"$libdir\"
134+
135+ exec_prefix="$acl_save_exec_prefix"
136+ prefix="$acl_save_prefix"
137+
138+ else
139+ additional_includedir="$withval/include"
140+ additional_libdir="$withval/lib"
141+ fi
142+ fi
143+
144+fi
145+
146+ LIBLZMA=
147+ LTLIBLZMA=
148+ INCLZMA=
149+ rpathdirs=
150+ ltrpathdirs=
151+ names_already_handled=
152+ names_next_round='lzma '
153+ while test -n "$names_next_round"; do
154+ names_this_round="$names_next_round"
155+ names_next_round=
156+ for name in $names_this_round; do
157+ already_handled=
158+ for n in $names_already_handled; do
159+ if test "$n" = "$name"; then
160+ already_handled=yes
161+ break
162+ fi
163+ done
164+ if test -z "$already_handled"; then
165+ names_already_handled="$names_already_handled $name"
166+ uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'`
167+ eval value=\"\$HAVE_LIB$uppername\"
168+ if test -n "$value"; then
169+ if test "$value" = yes; then
170+ eval value=\"\$LIB$uppername\"
171+ test -z "$value" || LIBLZMA="${LIBLZMA}${LIBLZMA:+ }$value"
172+ eval value=\"\$LTLIB$uppername\"
173+ test -z "$value" || LTLIBLZMA="${LTLIBLZMA}${LTLIBLZMA:+ }$value"
174+ else
175+ :
176+ fi
177+ else
178+ found_dir=
179+ found_la=
180+ found_so=
181+ found_a=
182+ if test $use_additional = yes; then
183+ if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext"; then
184+ found_dir="$additional_libdir"
185+ found_so="$additional_libdir/lib$name.$shlibext"
186+ if test -f "$additional_libdir/lib$name.la"; then
187+ found_la="$additional_libdir/lib$name.la"
188+ fi
189+ else
190+ if test -f "$additional_libdir/lib$name.$libext"; then
191+ found_dir="$additional_libdir"
192+ found_a="$additional_libdir/lib$name.$libext"
193+ if test -f "$additional_libdir/lib$name.la"; then
194+ found_la="$additional_libdir/lib$name.la"
195+ fi
196+ fi
197+ fi
198+ fi
199+ if test "X$found_dir" = "X"; then
200+ for x in $LDFLAGS $LTLIBLZMA; do
201+
202+ acl_save_prefix="$prefix"
203+ prefix="$acl_final_prefix"
204+ acl_save_exec_prefix="$exec_prefix"
205+ exec_prefix="$acl_final_exec_prefix"
206+ eval x=\"$x\"
207+ exec_prefix="$acl_save_exec_prefix"
208+ prefix="$acl_save_prefix"
209+
210+ case "$x" in
211+ -L*)
212+ dir=`echo "X$x" | sed -e 's/^X-L//'`
213+ if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; then
214+ found_dir="$dir"
215+ found_so="$dir/lib$name.$shlibext"
216+ if test -f "$dir/lib$name.la"; then
217+ found_la="$dir/lib$name.la"
218+ fi
219+ else
220+ if test -f "$dir/lib$name.$libext"; then
221+ found_dir="$dir"
222+ found_a="$dir/lib$name.$libext"
223+ if test -f "$dir/lib$name.la"; then
224+ found_la="$dir/lib$name.la"
225+ fi
226+ fi
227+ fi
228+ ;;
229+ esac
230+ if test "X$found_dir" != "X"; then
231+ break
232+ fi
233+ done
234+ fi
235+ if test "X$found_dir" != "X"; then
236+ LTLIBLZMA="${LTLIBLZMA}${LTLIBLZMA:+ }-L$found_dir -l$name"
237+ if test "X$found_so" != "X"; then
238+ if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/lib"; then
239+ LIBLZMA="${LIBLZMA}${LIBLZMA:+ }$found_so"
240+ else
241+ haveit=
242+ for x in $ltrpathdirs; do
243+ if test "X$x" = "X$found_dir"; then
244+ haveit=yes
245+ break
246+ fi
247+ done
248+ if test -z "$haveit"; then
249+ ltrpathdirs="$ltrpathdirs $found_dir"
250+ fi
251+ if test "$hardcode_direct" = yes; then
252+ LIBLZMA="${LIBLZMA}${LIBLZMA:+ }$found_so"
253+ else
254+ if test -n "$hardcode_libdir_flag_spec" && test "$hardcode_minus_L" = no; then
255+ LIBLZMA="${LIBLZMA}${LIBLZMA:+ }$found_so"
256+ haveit=
257+ for x in $rpathdirs; do
258+ if test "X$x" = "X$found_dir"; then
259+ haveit=yes
260+ break
261+ fi
262+ done
263+ if test -z "$haveit"; then
264+ rpathdirs="$rpathdirs $found_dir"
265+ fi
266+ else
267+ haveit=
268+ for x in $LDFLAGS $LIBLZMA; do
269+
270+ acl_save_prefix="$prefix"
271+ prefix="$acl_final_prefix"
272+ acl_save_exec_prefix="$exec_prefix"
273+ exec_prefix="$acl_final_exec_prefix"
274+ eval x=\"$x\"
275+ exec_prefix="$acl_save_exec_prefix"
276+ prefix="$acl_save_prefix"
277+
278+ if test "X$x" = "X-L$found_dir"; then
279+ haveit=yes
280+ break
281+ fi
282+ done
283+ if test -z "$haveit"; then
284+ LIBLZMA="${LIBLZMA}${LIBLZMA:+ }-L$found_dir"
285+ fi
286+ if test "$hardcode_minus_L" != no; then
287+ LIBLZMA="${LIBLZMA}${LIBLZMA:+ }$found_so"
288+ else
289+ LIBLZMA="${LIBLZMA}${LIBLZMA:+ }-l$name"
290+ fi
291+ fi
292+ fi
293+ fi
294+ else
295+ if test "X$found_a" != "X"; then
296+ LIBLZMA="${LIBLZMA}${LIBLZMA:+ }$found_a"
297+ else
298+ LIBLZMA="${LIBLZMA}${LIBLZMA:+ }-L$found_dir -l$name"
299+ fi
300+ fi
301+ additional_includedir=
302+ case "$found_dir" in
303+ */lib | */lib/)
304+ basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e 's,/lib/*$,,'`
305+ additional_includedir="$basedir/include"
306+ ;;
307+ esac
308+ if test "X$additional_includedir" != "X"; then
309+ if test "X$additional_includedir" != "X/usr/include"; then
310+ haveit=
311+ if test "X$additional_includedir" = "X/usr/local/include"; then
312+ if test -n "$GCC"; then
313+ case $host_os in
314+ linux*) haveit=yes;;
315+ esac
316+ fi
317+ fi
318+ if test -z "$haveit"; then
319+ for x in $CPPFLAGS $INCLZMA; do
320+
321+ acl_save_prefix="$prefix"
322+ prefix="$acl_final_prefix"
323+ acl_save_exec_prefix="$exec_prefix"
324+ exec_prefix="$acl_final_exec_prefix"
325+ eval x=\"$x\"
326+ exec_prefix="$acl_save_exec_prefix"
327+ prefix="$acl_save_prefix"
328+
329+ if test "X$x" = "X-I$additional_includedir"; then
330+ haveit=yes
331+ break
332+ fi
333+ done
334+ if test -z "$haveit"; then
335+ if test -d "$additional_includedir"; then
336+ INCLZMA="${INCLZMA}${INCLZMA:+ }-I$additional_includedir"
337+ fi
338+ fi
339+ fi
340+ fi
341+ fi
342+ if test -n "$found_la"; then
343+ save_libdir="$libdir"
344+ case "$found_la" in
345+ */* | *\\*) . "$found_la" ;;
346+ *) . "./$found_la" ;;
347+ esac
348+ libdir="$save_libdir"
349+ for dep in $dependency_libs; do
350+ case "$dep" in
351+ -L*)
352+ additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'`
353+ if test "X$additional_libdir" != "X/usr/lib"; then
354+ haveit=
355+ if test "X$additional_libdir" = "X/usr/local/lib"; then
356+ if test -n "$GCC"; then
357+ case $host_os in
358+ linux*) haveit=yes;;
359+ esac
360+ fi
361+ fi
362+ if test -z "$haveit"; then
363+ haveit=
364+ for x in $LDFLAGS $LIBLZMA; do
365+
366+ acl_save_prefix="$prefix"
367+ prefix="$acl_final_prefix"
368+ acl_save_exec_prefix="$exec_prefix"
369+ exec_prefix="$acl_final_exec_prefix"
370+ eval x=\"$x\"
371+ exec_prefix="$acl_save_exec_prefix"
372+ prefix="$acl_save_prefix"
373+
374+ if test "X$x" = "X-L$additional_libdir"; then
375+ haveit=yes
376+ break
377+ fi
378+ done
379+ if test -z "$haveit"; then
380+ if test -d "$additional_libdir"; then
381+ LIBLZMA="${LIBLZMA}${LIBLZMA:+ }-L$additional_libdir"
382+ fi
383+ fi
384+ haveit=
385+ for x in $LDFLAGS $LTLIBLZMA; do
386+
387+ acl_save_prefix="$prefix"
388+ prefix="$acl_final_prefix"
389+ acl_save_exec_prefix="$exec_prefix"
390+ exec_prefix="$acl_final_exec_prefix"
391+ eval x=\"$x\"
392+ exec_prefix="$acl_save_exec_prefix"
393+ prefix="$acl_save_prefix"
394+
395+ if test "X$x" = "X-L$additional_libdir"; then
396+ haveit=yes
397+ break
398+ fi
399+ done
400+ if test -z "$haveit"; then
401+ if test -d "$additional_libdir"; then
402+ LTLIBLZMA="${LTLIBLZMA}${LTLIBLZMA:+ }-L$additional_libdir"
403+ fi
404+ fi
405+ fi
406+ fi
407+ ;;
408+ -R*)
409+ dir=`echo "X$dep" | sed -e 's/^X-R//'`
410+ if test "$enable_rpath" != no; then
411+ haveit=
412+ for x in $rpathdirs; do
413+ if test "X$x" = "X$dir"; then
414+ haveit=yes
415+ break
416+ fi
417+ done
418+ if test -z "$haveit"; then
419+ rpathdirs="$rpathdirs $dir"
420+ fi
421+ haveit=
422+ for x in $ltrpathdirs; do
423+ if test "X$x" = "X$dir"; then
424+ haveit=yes
425+ break
426+ fi
427+ done
428+ if test -z "$haveit"; then
429+ ltrpathdirs="$ltrpathdirs $dir"
430+ fi
431+ fi
432+ ;;
433+ -l*)
434+ names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'`
435+ ;;
436+ *.la)
437+ names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'`
438+ ;;
439+ *)
440+ LIBLZMA="${LIBLZMA}${LIBLZMA:+ }$dep"
441+ LTLIBLZMA="${LTLIBLZMA}${LTLIBLZMA:+ }$dep"
442+ ;;
443+ esac
444+ done
445+ fi
446+ else
447+ LIBLZMA="${LIBLZMA}${LIBLZMA:+ }-l$name"
448+ LTLIBLZMA="${LTLIBLZMA}${LTLIBLZMA:+ }-l$name"
449+ fi
450+ fi
451+ fi
452+ done
453+ done
454+ if test "X$rpathdirs" != "X"; then
455+ if test -n "$hardcode_libdir_separator"; then
456+ alldirs=
457+ for found_dir in $rpathdirs; do
458+ alldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$found_dir"
459+ done
460+ acl_save_libdir="$libdir"
461+ libdir="$alldirs"
462+ eval flag=\"$hardcode_libdir_flag_spec\"
463+ libdir="$acl_save_libdir"
464+ LIBLZMA="${LIBLZMA}${LIBLZMA:+ }$flag"
465+ else
466+ for found_dir in $rpathdirs; do
467+ acl_save_libdir="$libdir"
468+ libdir="$found_dir"
469+ eval flag=\"$hardcode_libdir_flag_spec\"
470+ libdir="$acl_save_libdir"
471+ LIBLZMA="${LIBLZMA}${LIBLZMA:+ }$flag"
472+ done
473+ fi
474+ fi
475+ if test "X$ltrpathdirs" != "X"; then
476+ for found_dir in $ltrpathdirs; do
477+ LTLIBLZMA="${LTLIBLZMA}${LTLIBLZMA:+ }-R$found_dir"
478+ done
479+ fi
480+
481+
482+ ac_save_CPPFLAGS="$CPPFLAGS"
483+
484+ for element in $INCLZMA; do
485+ haveit=
486+ for x in $CPPFLAGS; do
487+
488+ acl_save_prefix="$prefix"
489+ prefix="$acl_final_prefix"
490+ acl_save_exec_prefix="$exec_prefix"
491+ exec_prefix="$acl_final_exec_prefix"
492+ eval x=\"$x\"
493+ exec_prefix="$acl_save_exec_prefix"
494+ prefix="$acl_save_prefix"
495+
496+ if test "X$x" = "X$element"; then
497+ haveit=yes
498+ break
499+ fi
500+ done
501+ if test -z "$haveit"; then
502+ CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }$element"
503+ fi
504+ done
505+
506+
507+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for liblzma" >&5
508+$as_echo_n "checking for liblzma... " >&6; }
509+if test "${ac_cv_liblzma+set}" = set; then :
510+ $as_echo_n "(cached) " >&6
511+else
512+
513+ ac_save_LIBS="$LIBS"
514+ LIBS="$LIBS $LIBLZMA"
515+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
516+/* end confdefs.h. */
517+#include "lzma.h"
518+int
519+main ()
520+{
521+lzma_index_iter iter;
522+ lzma_index_iter_init (&iter, 0);
523+ lzma_mf_is_supported (LZMA_MF_HC3);
524+ ;
525+ return 0;
526+}
527+_ACEOF
528+if ac_fn_c_try_link "$LINENO"; then :
529+ ac_cv_liblzma=yes
530+else
531+ ac_cv_liblzma=no
532+fi
533+rm -f core conftest.err conftest.$ac_objext \
534+ conftest$ac_exeext conftest.$ac_ext
535+ LIBS="$ac_save_LIBS"
536+
537+fi
538+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_liblzma" >&5
539+$as_echo "$ac_cv_liblzma" >&6; }
540+ if test "$ac_cv_liblzma" = yes; then
541+ HAVE_LIBLZMA=yes
542+
543+$as_echo "#define HAVE_LIBLZMA 1" >>confdefs.h
544+
545+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link with liblzma" >&5
546+$as_echo_n "checking how to link with liblzma... " >&6; }
547+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIBLZMA" >&5
548+$as_echo "$LIBLZMA" >&6; }
549+ else
550+ HAVE_LIBLZMA=no
551+ CPPFLAGS="$ac_save_CPPFLAGS"
552+ LIBLZMA=
553+ LTLIBLZMA=
554+ fi
555+
556+
557+
558+
559+
560+
561+ if test "$HAVE_LIBLZMA" != yes; then
562+ if test "$with_lzma" = yes; then
563+ as_fn_error "missing liblzma for --with-lzma" "$LINENO" 5
564+ fi
565+ fi
566+ fi
567+fi
568+
569 LIBGUI="../libgui/src/libgui.a"
570 GUI_CFLAGS_X="-I${srcdir}/../libgui/src"
571
572Index: gdb-7.4.91.20120801/gdb/configure.ac
573===================================================================
574--- gdb-7.4.91.20120801.orig/gdb/configure.ac 2012-08-01 18:45:21.000000000 +0200
575+++ gdb-7.4.91.20120801/gdb/configure.ac 2012-08-01 18:47:05.704820577 +0200
576@@ -2196,6 +2196,27 @@ LIBS=$OLD_LIBS
577 # Add any host-specific objects to GDB.
578 CONFIG_OBS="${CONFIG_OBS} ${gdb_host_obs}"
579
580+# If building on ELF, look for lzma support for embedded compressed debug info.
581+if test $gdb_cv_var_elf = yes; then
582+ AC_ARG_WITH(lzma,
583+ AS_HELP_STRING([--with-lzma], [support lzma compression (auto/yes/no)]),
584+ [], [with_lzma=auto])
585+ AC_MSG_CHECKING([whether to use lzma])
586+ AC_MSG_RESULT([$with_lzma])
587+
588+ if test "${with_lzma}" != no; then
589+ AC_LIB_HAVE_LINKFLAGS([lzma], [], [#include "lzma.h"],
590+ [lzma_index_iter iter;
591+ lzma_index_iter_init (&iter, 0);
592+ lzma_mf_is_supported (LZMA_MF_HC3);])
593+ if test "$HAVE_LIBLZMA" != yes; then
594+ if test "$with_lzma" = yes; then
595+ AC_MSG_ERROR([missing liblzma for --with-lzma])
596+ fi
597+ fi
598+ fi
599+fi
600+
601 LIBGUI="../libgui/src/libgui.a"
602 GUI_CFLAGS_X="-I${srcdir}/../libgui/src"
603 AC_SUBST(LIBGUI)
604Index: gdb-7.4.91.20120801/gdb/elfread.c
605===================================================================
606--- gdb-7.4.91.20120801.orig/gdb/elfread.c 2012-08-01 18:44:51.000000000 +0200
607+++ gdb-7.4.91.20120801/gdb/elfread.c 2012-08-01 18:57:59.528202398 +0200
608@@ -51,6 +51,10 @@
609 #include "observer.h"
610 #include "elf/external.h"
611 #include <sys/stat.h>
612+#include "gdbcore.h"
613+#ifdef HAVE_LIBLZMA
614+# include <lzma.h>
615+#endif
616
617 extern void _initialize_elfread (void);
618
619@@ -2210,6 +2214,262 @@ find_separate_debug_file_by_buildid (str
620 return NULL;
621 }
622
623+#ifdef HAVE_LIBLZMA
624+
625+/* Custom lzma_allocator.alloc so they use the gdb ones. */
626+
627+static void *
628+alloc_lzma (void *opaque, size_t nmemb, size_t size)
629+{
630+ return xmalloc (nmemb * size);
631+}
632+
633+/* Custom lzma_allocator.free so they use the gdb ones. */
634+
635+static void
636+free_lzma (void *opaque, void *ptr)
637+{
638+ xfree (ptr);
639+}
640+
641+/* It cannot be const due to the lzma library function prototypes. */
642+
643+static lzma_allocator gdb_lzma_allocator = { alloc_lzma, free_lzma, NULL};
644+
645+/* Custom bfd_openr_iovec implementation to read compressed data from a
646+ section. This keeps only the last decompressed block in memory to
647+ allow larger data without using to much memory. */
648+
649+struct lzma_stream
650+{
651+ /* Section of input BFD we are decoding data from. */
652+ asection *section;
653+
654+ /* lzma library decompression state. */
655+ lzma_index *index;
656+
657+ /* Currently decoded block. */
658+ bfd_size_type data_start;
659+ bfd_size_type data_end;
660+ gdb_byte *data;
661+};
662+
663+/* bfd_openr_iovec OPEN_P implementation for
664+ find_separate_debug_file_in_section. OPEN_CLOSURE is 'asection *' of the
665+ section to decompress.
666+
667+ Return 'struct lzma_stream *' must be freed by caller by xfree, together
668+ with its INDEX lzma data. */
669+
670+static void *
671+lzma_open (struct bfd *nbfd, void *open_closure)
672+{
673+ asection *section = open_closure;
674+ bfd_size_type size, offset;
675+ lzma_stream_flags options;
676+ gdb_byte footer[LZMA_STREAM_HEADER_SIZE];
677+ gdb_byte *indexdata;
678+ lzma_index *index;
679+ int ret;
680+ uint64_t memlimit = UINT64_MAX;
681+ struct lzma_stream *lstream;
682+ size_t pos;
683+
684+ size = bfd_get_section_size (section);
685+ offset = section->filepos + size - LZMA_STREAM_HEADER_SIZE;
686+ if (size < LZMA_STREAM_HEADER_SIZE
687+ || bfd_seek (section->owner, offset, SEEK_SET) != 0
688+ || bfd_bread (footer, LZMA_STREAM_HEADER_SIZE, section->owner)
689+ != LZMA_STREAM_HEADER_SIZE
690+ || lzma_stream_footer_decode (&options, footer) != LZMA_OK
691+ || offset < options.backward_size)
692+ {
693+ bfd_set_error (bfd_error_wrong_format);
694+ return NULL;
695+ }
696+
697+ offset -= options.backward_size;
698+ indexdata = xmalloc (options.backward_size);
699+ index = NULL;
700+ pos = 0;
701+ if (bfd_seek (section->owner, offset, SEEK_SET) != 0
702+ || bfd_bread (indexdata, options.backward_size, section->owner)
703+ != options.backward_size
704+ || lzma_index_buffer_decode (&index, &memlimit, &gdb_lzma_allocator,
705+ indexdata, &pos, options.backward_size)
706+ != LZMA_OK
707+ || lzma_index_size (index) != options.backward_size)
708+ {
709+ xfree (indexdata);
710+ bfd_set_error (bfd_error_wrong_format);
711+ return NULL;
712+ }
713+ xfree (indexdata);
714+
715+ lstream = xzalloc (sizeof (struct lzma_stream));
716+ lstream->section = section;
717+ lstream->index = index;
718+
719+ return lstream;
720+}
721+
722+/* bfd_openr_iovec PREAD_P implementation for
723+ find_separate_debug_file_in_section. Passed STREAM
724+ is 'struct lzma_stream *'. */
725+
726+static file_ptr
727+lzma_pread (struct bfd *nbfd, void *stream, void *buf, file_ptr nbytes,
728+ file_ptr offset)
729+{
730+ struct lzma_stream *lstream = stream;
731+ bfd_size_type chunk_size;
732+ lzma_index_iter iter;
733+ gdb_byte *compressed, *uncompressed;
734+ file_ptr block_offset;
735+ lzma_filter filters[LZMA_FILTERS_MAX + 1];
736+ lzma_block block;
737+ size_t compressed_pos, uncompressed_pos;
738+ file_ptr res;
739+
740+ res = 0;
741+ while (nbytes > 0)
742+ {
743+ if (lstream->data == NULL
744+ || lstream->data_start > offset || offset >= lstream->data_end)
745+ {
746+ asection *section = lstream->section;
747+
748+ lzma_index_iter_init (&iter, lstream->index);
749+ if (lzma_index_iter_locate (&iter, offset))
750+ break;
751+
752+ compressed = xmalloc (iter.block.total_size);
753+ block_offset = section->filepos + iter.block.compressed_file_offset;
754+ if (bfd_seek (section->owner, block_offset, SEEK_SET) != 0
755+ || bfd_bread (compressed, iter.block.total_size, section->owner)
756+ != iter.block.total_size)
757+ {
758+ xfree (compressed);
759+ break;
760+ }
761+
762+ uncompressed = xmalloc (iter.block.uncompressed_size);
763+
764+ memset (&block, 0, sizeof (block));
765+ block.filters = filters;
766+ block.header_size = lzma_block_header_size_decode (compressed[0]);
767+ if (lzma_block_header_decode (&block, &gdb_lzma_allocator, compressed)
768+ != LZMA_OK)
769+ {
770+ xfree (compressed);
771+ xfree (uncompressed);
772+ break;
773+ }
774+
775+ compressed_pos = block.header_size;
776+ uncompressed_pos = 0;
777+ if (lzma_block_buffer_decode (&block, &gdb_lzma_allocator,
778+ compressed, &compressed_pos,
779+ iter.block.total_size,
780+ uncompressed, &uncompressed_pos,
781+ iter.block.uncompressed_size)
782+ != LZMA_OK)
783+ {
784+ xfree (compressed);
785+ xfree (uncompressed);
786+ break;
787+ }
788+
789+ xfree (compressed);
790+
791+ xfree (lstream->data);
792+ lstream->data = uncompressed;
793+ lstream->data_start = iter.block.uncompressed_file_offset;
794+ lstream->data_end = (iter.block.uncompressed_file_offset
795+ + iter.block.uncompressed_size);
796+ }
797+
798+ chunk_size = min (nbytes, lstream->data_end - offset);
799+ memcpy (buf, lstream->data + offset - lstream->data_start, chunk_size);
800+ buf = (gdb_byte *) buf + chunk_size;
801+ offset += chunk_size;
802+ nbytes -= chunk_size;
803+ res += chunk_size;
804+ }
805+
806+ return res;
807+}
808+
809+/* bfd_openr_iovec CLOSE_P implementation for
810+ find_separate_debug_file_in_section. Passed STREAM
811+ is 'struct lzma_stream *'. */
812+
813+static int
814+lzma_close (struct bfd *nbfd,
815+ void *stream)
816+{
817+ struct lzma_stream *lstream = stream;
818+
819+ lzma_index_end (lstream->index, &gdb_lzma_allocator);
820+ xfree (lstream->data);
821+ xfree (lstream);
822+ return 0;
823+}
824+
825+/* bfd_openr_iovec STAT_P implementation for
826+ find_separate_debug_file_in_section. Passed STREAM
827+ is 'struct lzma_stream *'. */
828+
829+static int
830+lzma_stat (struct bfd *abfd,
831+ void *stream,
832+ struct stat *sb)
833+{
834+ struct lzma_stream *lstream = stream;
835+
836+ sb->st_size = lzma_index_uncompressed_size (lstream->index);
837+ return 0;
838+}
839+
840+/* This looks for a xz compressed separate debug info object file embedded
841+ in a section called .gnu_debugdata. If we find one we create a iovec
842+ based bfd that decompresses the object data on demand. */
843+
844+static bfd *
845+find_separate_debug_file_in_section (struct objfile *objfile)
846+{
847+ asection *section;
848+ bfd *abfd;
849+
850+ section = bfd_get_section_by_name (objfile->obfd, ".gnu_debugdata");
851+ if (section == NULL)
852+ return NULL;
853+
854+ /* objfile->NAME lifetime is longer than the ABFD's lifetime. */
855+ abfd = gdb_bfd_openr_iovec (objfile->name, gnutarget, lzma_open, section,
856+ lzma_pread, lzma_close, lzma_stat);
857+ if (abfd == NULL)
858+ return NULL;
859+
860+ if (!bfd_check_format (abfd, bfd_object))
861+ {
862+ gdb_bfd_unref (abfd);
863+ return NULL;
864+ }
865+
866+ return abfd;
867+}
868+
869+#else /* !HAVE_LIBLZMA */
870+
871+static bfd *
872+find_separate_debug_file_in_section (struct objfile *objfile)
873+{
874+ return NULL;
875+}
876+
877+#endif /* !HAVE_LIBLZMA */
878+
879 /* Scan and build partial symbols for a symbol file.
880 We have been initialized by a call to elf_symfile_init, which
881 currently does nothing.
882@@ -2433,6 +2693,8 @@ elf_symfile_read (struct objfile *objfil
883 else if (!objfile_has_partial_symbols (objfile))
884 {
885 char *debugfile, *build_id_filename;
886+ bfd *abfd = NULL;
887+ struct cleanup *cleanup;
888
889 debugfile = find_separate_debug_file_by_buildid (objfile,
890 &build_id_filename);
891@@ -2440,14 +2702,11 @@ elf_symfile_read (struct objfile *objfil
892 if (debugfile == NULL)
893 debugfile = find_separate_debug_file_by_debuglink (objfile);
894
895+ cleanup = make_cleanup (xfree, debugfile);
896 if (debugfile)
897 {
898- struct cleanup *cleanup = make_cleanup (xfree, debugfile);
899- bfd *abfd = symfile_bfd_open (debugfile);
900-
901+ abfd = symfile_bfd_open (debugfile);
902 make_cleanup_bfd_unref (abfd);
903- symbol_file_add_separate (abfd, symfile_flags, objfile);
904- do_cleanups (cleanup);
905 }
906 /* Check if any separate debug info has been extracted out. */
907 else if (bfd_get_section_by_name (objfile->obfd, ".gnu_debuglink")
908@@ -2455,6 +2714,17 @@ elf_symfile_read (struct objfile *objfil
909 debug_print_missing (objfile->name, build_id_filename);
910
911 xfree (build_id_filename);
912+
913+ if (abfd == NULL)
914+ {
915+ abfd = find_separate_debug_file_in_section (objfile);
916+ make_cleanup_bfd_unref (abfd);
917+ }
918+
919+ if (abfd != NULL)
920+ symbol_file_add_separate (abfd, symfile_flags, objfile);
921+
922+ do_cleanups (cleanup);
923 }
924
925 if (symtab_create_debug)
926Index: gdb-7.4.91.20120801/gdb/testsuite/gdb.dwarf2/dw2-gnu-debugdata.c
927===================================================================
928--- /dev/null 1970-01-01 00:00:00.000000000 +0000
929+++ gdb-7.4.91.20120801/gdb/testsuite/gdb.dwarf2/dw2-gnu-debugdata.c 2012-08-01 18:47:05.705820572 +0200
930@@ -0,0 +1,30 @@
931+/* This testcase is part of GDB, the GNU debugger.
932+
933+ Copyright 2012 Free Software Foundation, Inc.
934+
935+ This program is free software; you can redistribute it and/or modify
936+ it under the terms of the GNU General Public License as published by
937+ the Free Software Foundation; either version 3 of the License, or
938+ (at your option) any later version.
939+
940+ This program is distributed in the hope that it will be useful,
941+ but WITHOUT ANY WARRANTY; without even the implied warranty of
942+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
943+ GNU General Public License for more details.
944+
945+ You should have received a copy of the GNU General Public License
946+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
947+
948+#include <signal.h>
949+
950+static int
951+debugdata_function (void)
952+{
953+ return raise (SIGSEGV) + 1;
954+}
955+
956+int
957+main (void)
958+{
959+ return debugdata_function () + 1;
960+}
961Index: gdb-7.4.91.20120801/gdb/testsuite/gdb.dwarf2/dw2-gnu-debugdata.exp
962===================================================================
963--- /dev/null 1970-01-01 00:00:00.000000000 +0000
964+++ gdb-7.4.91.20120801/gdb/testsuite/gdb.dwarf2/dw2-gnu-debugdata.exp 2012-08-01 18:47:05.705820572 +0200
965@@ -0,0 +1,91 @@
966+# Copyright 2012 Free Software Foundation, Inc.
967+#
968+# This program is free software; you can redistribute it and/or modify
969+# it under the terms of the GNU General Public License as published by
970+# the Free Software Foundation; either version 3 of the License, or
971+# (at your option) any later version.
972+#
973+# This program is distributed in the hope that it will be useful,
974+# but WITHOUT ANY WARRANTY; without even the implied warranty of
975+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
976+# GNU General Public License for more details.
977+#
978+# You should have received a copy of the GNU General Public License
979+# along with this program. If not, see <http://www.gnu.org/licenses/>.
980+
981+standard_testfile
982+
983+load_lib dwarf.exp
984+if ![dwarf2_support] {
985+ return 0
986+}
987+
988+if [build_executable ${testfile}.exp $testfile] {
989+ return -1
990+}
991+
992+proc run { test cmdline } {
993+ verbose "cmdline is $cmdline"
994+ set result [catch "exec $cmdline" output]
995+ verbose "result is $result"
996+ verbose "output is $output"
997+ if {$result == 0} {
998+ pass $test
999+ return 0
1000+ } else {
1001+ fail $test
1002+ return -1
1003+ }
1004+}
1005+
1006+set strip_program [transform strip]
1007+set nm_program [transform nm]
1008+
1009+# Extract the dynamic symbols from the main binary, there is no need to also have these
1010+# in the normal symbol table
1011+file delete -- ${binfile}.dynsyms
1012+if [run "nm -D" "[transform nm] -D ${binfile} --format=posix --defined-only | awk \\{print\\ \\\$1\\} | sort > ${binfile}.dynsyms"] {
1013+ return -1
1014+}
1015+
1016+# Extract all the text (i.e. function) symbols from the debuginfo
1017+file delete -- ${binfile}.funcsyms
1018+if [run "nm" "[transform nm] ${binfile} --format=posix --defined-only | awk \\{if(\\\$2==\"T\"||\\\$2==\"t\")print\\ \\\$1\\} | sort > ${binfile}.funcsyms"] {
1019+ return -1
1020+}
1021+
1022+# Keep all the function symbols not already in the dynamic symbol table
1023+file delete -- ${binfile}.keep_symbols
1024+if [run "comm" "comm -13 ${binfile}.dynsyms ${binfile}.funcsyms > ${binfile}.keep_symbols"] {
1025+ return -1
1026+}
1027+
1028+# Copy the full debuginfo, keeping only a minumal set of symbols and removing some unnecessary sections
1029+file delete -- ${binfile}.mini_debuginfo
1030+if [run "objcopy 1" "[transform objcopy] -S --remove-section .gdb_index --remove-section .comment --keep-symbols=${binfile}.keep_symbols ${binfile} ${binfile}.mini_debuginfo"] {
1031+ return -1
1032+}
1033+
1034+# GDB specific - we do not have split executable in advance.
1035+file delete -- ${binfile}.strip
1036+if [run "strip" "[transform strip] --strip-all -o ${binfile}.strip ${binfile}"] {
1037+ return -1
1038+}
1039+
1040+# Inject the compressed data into the .gnu_debugdata section of the original binary
1041+file delete -- ${binfile}.mini_debuginfo.xz
1042+if [run "xz" "xz ${binfile}.mini_debuginfo"] {
1043+ return -1
1044+}
1045+file delete -- ${binfile}.test
1046+if [run "objcopy 2" "[transform objcopy] --add-section .gnu_debugdata=${binfile}.mini_debuginfo.xz ${binfile}.strip ${binfile}.test"] {
1047+ return -1
1048+}
1049+
1050+clean_restart "$testfile.strip"
1051+
1052+gdb_test "p debugdata_function" {No symbol table is loaded\. Use the "file" command\.} "no symtab"
1053+
1054+clean_restart "$testfile.test"
1055+
1056+gdb_test "p debugdata_function" { = {<text variable, no debug info>} 0x[0-9a-f]+ <debugdata_function>} "have symtab"
This page took 0.229564 seconds and 4 git commands to generate.