1 /* bug-buddy bug submitting program
3 * Copyright (C) 2008 - 2010 Fernando Herrera <fherrera@onirica.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
33 find_in_debug_path (const char *filename
, const char *debug_filename
)
37 gboolean result
= FALSE
;
40 dir
= g_path_get_dirname (filename
);
41 tries
[0] = g_build_filename (dir
, debug_filename
, NULL
);
42 tries
[1] = g_build_filename (dir
, ".debug", debug_filename
, NULL
);
43 tries
[2] = g_build_filename ("/usr", "lib", "debug", dir
, debug_filename
, NULL
);
47 for (i
= 0; i
< N_TRIES
; ++i
) {
48 if (g_file_test (tries
[i
], G_FILE_TEST_EXISTS
)) {
54 for (i
= 0; i
< N_TRIES
; i
++)
62 elf_has_debug_symbols (gint pid
)
74 if (elf_version (EV_CURRENT
) == EV_NONE
) {
75 fprintf(stderr
, "Elf library out of date!n");
79 proc_path
= g_strdup_printf ("/proc/%d/exe", pid
);
80 filename
= g_file_read_link (proc_path
, NULL
);
85 fd
= open (filename
, O_RDONLY
);
87 if ((elf
= elf_begin (fd
, ELF_C_READ
, NULL
)) == NULL
){
91 gelf_getehdr (elf
, &elf_header
);
92 while ((section
= elf_nextscn (elf
, section
)) != 0) {
95 /* Check for stabs debug information */
96 if (gelf_getshdr (section
, &shdr
) != 0) {
97 if (shdr
.sh_type
== SHT_SYMTAB
) {
103 /* Check for .gnu_debuglink separete debug file */
104 if (shdr
.sh_type
== SHT_PROGBITS
) {
105 char *name
= elf_strptr(elf
, elf_header
.e_shstrndx
, shdr
.sh_name
);
106 if (strcmp (name
, ".gnu_debuglink") == 0) {
109 edata
= elf_getdata(section
, NULL
);
110 if (edata
!= NULL
&& find_in_debug_path (filename
, (const char*) edata
->d_buf
)) {
118 /* no symtab neither debug file present */