From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 40838 invoked by alias); 17 Aug 2015 16:00:31 -0000 Mailing-List: contact archer-commits-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: Received: (qmail 40791 invoked by uid 9674); 17 Aug 2015 16:00:26 -0000 Date: Mon, 17 Aug 2015 16:00:00 -0000 Message-ID: <20150817160026.40712.qmail@sourceware.org> From: jkratoch@sourceware.org To: archer-commits@sourceware.org Subject: [SCM] jankratochvil/gdbserverbuildid: mainbuildid X-Git-Refname: refs/heads/jankratochvil/gdbserverbuildid X-Git-Reftype: branch X-Git-Oldrev: ea8ad7ecbd272bdfaaa28fbef8dbd24cd14caa8a X-Git-Newrev: aa180b0c7f35cb8f20ffec5d74e9c63a88b422a0 X-SW-Source: 2015-q3/txt/msg00033.txt.bz2 List-Id: The branch, jankratochvil/gdbserverbuildid has been updated discards ea8ad7ecbd272bdfaaa28fbef8dbd24cd14caa8a (commit) discards ad89a2f824135c905c231a78d9627e6589bb4a95 (commit) discards 4874f3b58bb2c74b62ec7227fbe41386fb5d8007 (commit) discards 5353e034a77740ff0ef0ee48eb9d0f7af01e8307 (commit) discards 82e9f636c521d9ecdf804a9072170177e8e793b3 (commit) discards cd79c4492a000a36649464257cea46def250391c (commit) discards 08ad08f1e4305221a4513ec87e1d5d085c3d4fab (commit) discards 177660d6a8d4f4ba1660fc61b49da42cdf96eb9e (commit) discards 8db972fd3127ea419267b3b235cd7b00b9fe875d (commit) discards a3b70f44851d42fc06a9f94b01ab687440ea19c2 (commit) discards c4c90a0f7bc8317cb962c499ede1208790a9253a (commit) discards c4ef17e38205ff1559a58e3bdd5f6ef92ecda89b (commit) discards 0d00d3a8d93e6ac23d29c7c8e53f1dfc1666a822 (commit) discards 4600db9a5cc528a655a1ebe92d477209d7146800 (commit) discards c1d8b72d24a6123eb8648bdbc1b2e3a56e282bc6 (commit) discards 87d3c70eb6acd1584f17ff27dbfa7853fe0ea9ed (commit) discards 2fce2213eba7e5446979a0ce2d032b1acb621aaf (commit) discards 12f3de0ea0fb4c5d60f5fad73c6f054bd1e0fea1 (commit) discards 8db0b61178445252d6c43384784728b71b7f3f05 (commit) discards e600bf60a682090eb325052245a7c79aba73ff77 (commit) discards 99c41f79be7c1437c8499d632fd13e8ae7d36c32 (commit) discards 06214010ff8650436a4021a8536af52a19e4c748 (commit) discards 418b022857bb6be73630d795ff6ccb818145a566 (commit) discards 79df217f6235b3fc200668fd39dfe38df1dafc44 (commit) discards 47c49eb97dcc9ff751e977d5a57f48e27333c59d (commit) discards 4ab6b65563fb705f0dc5a45396e429995f6dd25c (commit) via aa180b0c7f35cb8f20ffec5d74e9c63a88b422a0 (commit) via 37b4f6ecd060252c96287ecc5e6c17476065b37d (commit) via 37b7a7dc41042cd194d42e4b51ec62a76b67909f (commit) via e70bc7d408e34e531db1a3374fc4d8ba3966727f (commit) via b10b37757831c1d24112dae16c956a5aced002c8 (commit) via 4db67c2978ebc2bab19838a0a4dc938595541856 (commit) via 1fbb639307854a32484a4c24440214cd095b1dd3 (commit) via c5420b36ebe6cee180207253abb8c5807828f51c (commit) via f2291abd5dd1bf7eb65d304cd59da2ef00c4820f (commit) via 0e45553a30b2b8b8adeb0a00a0eed1ab0f37eabf (commit) via 3a8a0b30b2dccbed430eb6c38da165a9fde1feef (commit) via cfe1119c0322114641aee215f9e5f5293b723e82 (commit) via ab4afa2535c0182dc528a1e867c3f57b5d8292c4 (commit) via ff4f9d48102ed472ca527b52640fabc5f750c2cc (commit) via 3754f48adfbdb91c9005e8945f910772c76e1c26 (commit) via 15ee2159ec7f57bd4daa3e404baa41cee9f76637 (commit) via 14cc6806a7ea29ab4b66d7353952d4a05d86ed89 (commit) via 4ad6a791530bc04da99b523d6e7510b195d2543f (commit) via 0f7e18c01c27f2b1ad53c6f8882db8752405ebb9 (commit) via 46a81d5758e65c73e7e4eaf5257c6ff341c068a3 (commit) via 51a6ed4c87273fe52e81b7947dd4ee3c878d3870 (commit) via 116a250b31b5665873c7c58da676528520565f40 (commit) via 6ae7a094e89cdcb07d56586f8c3b9986f0bce700 (commit) via 5ca7075e738daca657d39426377c29632e832b07 (commit) via 7038751dcc9c65cf412ff977869d614d233d7aa0 (commit) via af7cb14bcbbcaabbc8e0edb9dbe99e2ca4d56af3 (commit) from ea8ad7ecbd272bdfaaa28fbef8dbd24cd14caa8a (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit aa180b0c7f35cb8f20ffec5d74e9c63a88b422a0 Author: Jan Kratochvil Date: Thu Aug 13 16:17:19 2015 +0200 mainbuildid commit 37b4f6ecd060252c96287ecc5e6c17476065b37d Author: Jan Kratochvil Date: Sun Aug 16 22:11:19 2015 +0200 sticky Message-ID: <559A7C37.6020501@redhat.com> On 07/03/2015 04:44 PM, Pedro Alves wrote: > (I still suspect that if we reverse the sense of the flag, then > its management ends up being more centralized, as then the > place that sets it is also the place that needs to check it, > instead of doing that in multiple places. But, see below.) It didn't seem fair to impose a subjective preference, so I tried this in order to understand it myself, and I now agree that is really doesn't make much difference, as then we'd have to mark auto-discovered in a few more places that I wasn't originally seeing. There's at least the execd handling in infrun.c, and also spu_symbol_file_add_from_memory. As I was playing with this already, I poked at the other review points I made, and came up with the variant of the patch below. > This function is called while the passed in PID is not the > current inferior. E.g., the remote_add_inferior path. > > Therefore seems to me that these symbol_file_add_main / exec_file_attach > calls can change the symbols of the wrong inferior. ... > I also notice that reread_symbols has an exec_file_attach > call which seems to me results in losing the is_user_supplied > flag if the executable's timestamp changed, at least here: > >> + /* Attempt to open the file that was executed to create this >> + inferior. If the user has explicitly specified executable >> + and/or symbol files then warn the user if their choices do >> + not match. Otherwise, set exec_file and symfile_objfile to >> + the new file. */ >> + exec_file_locate_attach (ptid_get_pid (inferior_ptid), from_tty); >> + >> + if (exec_file_is_user_supplied) >> { >> reopen_exec_file (); >> reread_symbols (); > > > I also notice that the clone-inferior command ends up with > an exec_file_attach call in clone_program_space. That one > should probably be setting the is_user_supplied flag too, > I'd think. Or at least, copying it from the original. > > At this point, I'm wondering about adding a parameter to > exec_file_attach to force considering (now and in future) > the right value to put in the flag in each case. I tried this too (see patch below). As this requires touching the user-supplied paths anyway, it didn't really matter to tag files user-supplied or auto-discovered, so I reverted back to user-supplied. For symbols, we already have the add_flags, so I added SYMFILE_USER_SUPPLIED instead of a new boolean. > >> @@ -2490,11 +2490,14 @@ attach_command_post_wait (char *args, int from_tty, int async_exec) >> inferior = current_inferior (); >> inferior->control.stop_soon = NO_STOP_QUIETLY; >> >> - /* If no exec file is yet known, try to determine it from the >> - process itself. */ >> - if (get_exec_file (0) == NULL) >> - exec_file_locate_attach (ptid_get_pid (inferior_ptid), from_tty); >> - else >> + /* Attempt to open the file that was executed to create this >> + inferior. If the user has explicitly specified executable >> + and/or symbol files then warn the user if their choices do >> + not match. Otherwise, set exec_file and symfile_objfile to >> + the new file. */ >> + exec_file_locate_attach (ptid_get_pid (inferior_ptid), from_tty); >> + >> + if (exec_file_is_user_supplied) >> { >> reopen_exec_file (); >> reread_symbols (); > > It seems to me that we should be able to move these reopen/reread > calls inside exec_file_locate_attach. I did this too. What do you think of the version below? I also tweaked the warnings a bit, to explicitly say "mismatch". This would still need docs/NEWS changes, and a test would be good too. commit 37b7a7dc41042cd194d42e4b51ec62a76b67909f Author: Jan Kratochvil Date: Thu Aug 13 16:17:19 2015 +0200 hexallocate commit e70bc7d408e34e531db1a3374fc4d8ba3966727f Author: Jan Kratochvil Date: Thu Aug 13 16:17:19 2015 +0200 locatetest commit b10b37757831c1d24112dae16c956a5aced002c8 Author: Jan Kratochvil Date: Thu Aug 13 16:17:19 2015 +0200 Tests for validate symbol file using build-id New testcase. gdb/testsuite/ChangeLog 2015-07-15 Aleksandar Ristovski Date: Thu Aug 13 16:17:18 2015 +0200 buildidwarn commit 1fbb639307854a32484a4c24440214cd095b1dd3 Author: Jan Kratochvil Date: Thu Aug 13 16:17:18 2015 +0200 buildidsolibbfdopen commit c5420b36ebe6cee180207253abb8c5807828f51c Author: Jan Kratochvil Date: Thu Aug 13 16:17:18 2015 +0200 buildidverify commit f2291abd5dd1bf7eb65d304cd59da2ef00c4820f Author: Jan Kratochvil Date: Thu Aug 13 16:17:18 2015 +0200 buildidsolibsearch commit 0e45553a30b2b8b8adeb0a00a0eed1ab0f37eabf Author: Jan Kratochvil Date: Thu Aug 13 16:17:18 2015 +0200 buildidtofile commit 3a8a0b30b2dccbed430eb6c38da165a9fde1feef Author: Jan Kratochvil Date: Thu Aug 13 16:17:17 2015 +0200 buildidproto commit cfe1119c0322114641aee215f9e5f5293b723e82 Author: Jan Kratochvil Date: Thu Aug 13 16:17:17 2015 +0200 buildidtobfd commit ab4afa2535c0182dc528a1e867c3f57b5d8292c4 Author: Jan Kratochvil Date: Thu Aug 13 16:17:17 2015 +0200 buildidforcemove commit ff4f9d48102ed472ca527b52640fabc5f750c2cc Author: Jan Kratochvil Date: Thu Aug 13 16:17:17 2015 +0200 buildidfreefix commit 3754f48adfbdb91c9005e8945f910772c76e1c26 Author: Jan Kratochvil Date: Thu Aug 13 16:17:16 2015 +0200 openpsymfile commit 15ee2159ec7f57bd4daa3e404baa41cee9f76637 Author: Jan Kratochvil Date: Thu Aug 13 16:17:16 2015 +0200 openpsolib commit 14cc6806a7ea29ab4b66d7353952d4a05d86ed89 Author: Jan Kratochvil Date: Thu Aug 13 16:17:16 2015 +0200 openp commit 4ad6a791530bc04da99b523d6e7510b195d2543f Author: Jan Kratochvil Date: Thu Aug 13 16:17:16 2015 +0200 filelib commit 0f7e18c01c27f2b1ad53c6f8882db8752405ebb9 Author: Jan Kratochvil Date: Thu Aug 13 16:17:15 2015 +0200 openfromtargetdoclose commit 46a81d5758e65c73e7e4eaf5257c6ff341c068a3 Author: Jan Kratochvil Date: Thu Aug 13 16:17:15 2015 +0200 openfromtargetfd commit 51a6ed4c87273fe52e81b7947dd4ee3c878d3870 Author: Jan Kratochvil Date: Thu Aug 13 16:17:15 2015 +0200 openfromtarget commit 116a250b31b5665873c7c58da676528520565f40 Author: Jan Kratochvil Date: Thu Aug 13 16:17:14 2015 +0200 openpnullpathname commit 6ae7a094e89cdcb07d56586f8c3b9986f0bce700 Author: Jan Kratochvil Date: Thu Aug 13 16:17:14 2015 +0200 openpmode commit 5ca7075e738daca657d39426377c29632e832b07 Author: Jan Kratochvil Date: Thu Aug 13 16:17:14 2015 +0200 openppath commit 7038751dcc9c65cf412ff977869d614d233d7aa0 Author: Jan Kratochvil Date: Thu Aug 13 16:17:13 2015 +0200 openpenum commit af7cb14bcbbcaabbc8e0edb9dbe99e2ca4d56af3 Author: Jan Kratochvil Date: Thu Aug 13 16:17:13 2015 +0200 sysrootdefault ----------------------------------------------------------------------- Summary of changes: gdb/cli/cli-cmds.c | 2 +- gdb/defs.h | 4 +- gdb/dwarf2read.c | 2 +- gdb/exec.c | 10 ++- gdb/infrun.c | 2 +- gdb/solib-svr4.c | 18 +++ gdb/solib.c | 16 +++- gdb/solist.h | 12 ++- gdb/source.c | 10 +- gdb/testsuite/gdb.base/attach.exp | 7 +- gdb/testsuite/gdb.base/main-mismatch-mod.c | 39 ++++++ gdb/testsuite/gdb.base/main-mismatch.c | 39 ++++++ gdb/testsuite/gdb.base/main-mismatch.exp | 178 ++++++++++++++++++++++++++++ 13 files changed, 323 insertions(+), 16 deletions(-) create mode 100644 gdb/testsuite/gdb.base/main-mismatch-mod.c create mode 100644 gdb/testsuite/gdb.base/main-mismatch.c create mode 100644 gdb/testsuite/gdb.base/main-mismatch.exp First 500 lines of diff: diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 5be758d..2af76a2 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -510,7 +510,7 @@ find_and_open_script (const char *script_file, int search_path, /* Search for and open 'file' on the search path used for source files. Put the full location in *FULL_PATHP. */ - fd = openp (source_path, search_flags, file, full_pathp); + fd = openp (source_path, search_flags, file, 0 /* build_idsz */, NULL /* build_id */, full_pathp); if (fd == -1) { diff --git a/gdb/defs.h b/gdb/defs.h index 0011635..f4bdbe1 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -329,13 +329,13 @@ enum openp_flags OPF_BFD_CANONICAL = (1 << 3), }; -extern int openp (const char *, enum openp_flags, const char *, char **); +extern int openp (const char *, enum openp_flags, const char *, size_t build_idsz, const gdb_byte *build_id, char **); extern bfd *openp_bfd (const char *path, enum openp_flags opts, const char *string); extern struct file_location openp_file (const char *path, enum openp_flags opts, const char *string, size_t build_idsz, const gdb_byte *build_id); -extern int source_full_path_of (const char *, char **); +extern int source_full_path_of (const char *, size_t build_idsz, const gdb_byte *build_id, char **); extern void mod_path (char *, char **); diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 332f102..b2463da 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -10500,7 +10500,7 @@ try_open_dwop_file (const char *file_name, int is_dwp, int search_cwd) flags = 0; if (is_dwp) flags |= OPF_SEARCH_IN_PATH; - desc = openp (search_path, flags, file_name, &absolute_name); + desc = openp (search_path, flags, file_name, 0 /* build_idsz */, NULL /* build_id */, &absolute_name); xfree (search_path); if (desc < 0) return NULL; diff --git a/gdb/exec.c b/gdb/exec.c index 4ec321b..aeec5c2 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -152,10 +152,16 @@ exec_file_and_symbols_resync (struct inferior *inf, int from_tty) exec_file = target_pid_to_exec_file (inf->pid); if (exec_file != NULL) { + size_t build_idsz; + gdb_byte *build_id; + + solib_main_build_id (&build_idsz, &build_id); + make_cleanup (xfree, build_id); + /* If gdb_sysroot is not empty and the discovered filename is absolute then prefix the filename with gdb_sysroot. */ if (*gdb_sysroot != '\0' && IS_ABSOLUTE_PATH (exec_file)) - full_exec_path = exec_file_find (exec_file, NULL); + full_exec_path = exec_file_find (exec_file, build_idsz, build_id, NULL); if (full_exec_path == NULL) { @@ -166,7 +172,7 @@ exec_file_and_symbols_resync (struct inferior *inf, int from_tty) Attempt to qualify the filename against the source path. (If that fails, we'll just fall back on the original filename. Not much more we can do...) */ - if (!source_full_path_of (exec_file, &full_exec_path)) + if (!source_full_path_of (exec_file, build_idsz, build_id, &full_exec_path)) full_exec_path = xstrdup (exec_file); } } diff --git a/gdb/infrun.c b/gdb/infrun.c index 44d2e06..46d14db 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -1165,7 +1165,7 @@ follow_exec (ptid_t ptid, char *execd_pathname) if (*gdb_sysroot != '\0') { - char *name = exec_file_find (execd_pathname, NULL); + char *name = exec_file_find (execd_pathname, 0 /* build_idsz */, NULL /* build_id */, NULL); execd_pathname = alloca (strlen (name) + 1); strcpy (execd_pathname, name); diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index f15ea02..196c96a 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -1592,6 +1592,23 @@ svr4_current_sos_1 (void) return svr4_current_sos_direct (info); } +static void +svr4_main_build_id (size_t *build_idszp, gdb_byte **build_idp) +{ + struct svr4_info *info = get_svr4_info (); + + /* If the solib list has been read and stored by the probes + interface then even main_build_id should be valid there. */ + if (info->solib_list == NULL) + svr4_current_sos_direct (info); + + *build_idszp = info->main_build_idsz; + if (*build_idszp == 0) + *build_idp = NULL; + else + *build_idp = xmemdup (info->main_build_id, *build_idszp, *build_idszp); +} + /* Implement the "current_sos" target_so_ops method. */ static struct so_list * @@ -3355,6 +3372,7 @@ _initialize_svr4_solib (void) svr4_so_ops.special_symbol_handling = svr4_special_symbol_handling; svr4_so_ops.current_sos = svr4_current_sos; svr4_so_ops.open_symbol_file_object = open_symbol_file_object; + svr4_so_ops.main_build_id = svr4_main_build_id; svr4_so_ops.in_dynsym_resolve_code = svr4_in_dynsym_resolve_code; svr4_so_ops.bfd_open = solib_bfd_open; svr4_so_ops.lookup_lib_global_symbol = elf_lookup_lib_symbol; diff --git a/gdb/solib.c b/gdb/solib.c index b343df0..6b5e61d 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -470,7 +470,7 @@ solib_find_1 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id, above. */ char * -exec_file_find (char *in_pathname, int *fd) +exec_file_find (char *in_pathname, size_t build_idsz, const gdb_byte *build_id, int *fd) { char *result = solib_find_1 (in_pathname, 0 /* build_idsz */, NULL /* build_id */, fd, 0 /* is_solib */); @@ -1642,6 +1642,20 @@ solib_global_lookup (struct objfile *objfile, return (struct block_symbol) {NULL, NULL}; } +/* See solist.h. */ + +void +solib_main_build_id (size_t *build_idszp, gdb_byte **build_idp) +{ + const struct target_so_ops *ops = ops = solib_ops (target_gdbarch ()); + + if (ops->main_build_id != NULL) + return ops->main_build_id (build_idszp, build_idp); + + *build_idszp = 0; + *build_idp = NULL; +} + /* Lookup the value for a specific symbol from dynamic symbol table. Look up symbol from ABFD. MATCH_SYM is a callback function to determine whether to pick up a symbol. DATA is the input of this callback diff --git a/gdb/solist.h b/gdb/solist.h index e189183..c13aed1 100644 --- a/gdb/solist.h +++ b/gdb/solist.h @@ -135,6 +135,13 @@ struct target_so_ops catch_errors requires a pointer argument. */ int (*open_symbol_file_object) (void *from_ttyp); + /* Report build-id of the main executable. Both BUILD_IDSZP and + BUILD_IDP must not be NULL. If returned *BUILD_IDSZP is zero + build-id is not known. Returned *BUILD_IDP must be xfree-d by + the caller. This pointer can be NULL, in which case this + functionality is not supported for this target. */ + void (*main_build_id) (size_t *build_idszp, gdb_byte **build_idp); + /* Determine if PC lies in the dynamic symbol resolution code of the run time loader. */ int (*in_dynsym_resolve_code) (CORE_ADDR pc); @@ -188,7 +195,7 @@ void free_so (struct so_list *so); struct so_list *master_so_list (void); /* Find main executable binary file. */ -extern char *exec_file_find (char *in_pathname, int *fd); +extern char *exec_file_find (char *in_pathname, size_t build_idsz, const gdb_byte *build_id, int *fd); /* Find shared library binary file. */ extern char *solib_find (char *in_pathname, size_t build_idsz, @@ -209,4 +216,7 @@ struct block_symbol solib_global_lookup (struct objfile *objfile, const char *name, const domain_enum domain); +/* See target_so_ops's main_build_id. */ +void solib_main_build_id (size_t *build_idszp, gdb_byte **build_idp); + #endif diff --git a/gdb/source.c b/gdb/source.c index 2b3650d..a7e2561 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -955,7 +955,7 @@ filename_to_bfd (const char *filename) } int -openp (const char *path, enum openp_flags opts, const char *string, char **filename_opened) +openp (const char *path, enum openp_flags opts, const char *string, size_t build_idsz, const gdb_byte *build_id, char **filename_opened) { struct file_location file; int retval; @@ -1180,12 +1180,12 @@ openp_file (const char *path, enum openp_flags opts, const char *string, size_t Else, this functions returns 0, and FULL_PATHNAME is set to NULL. */ int -source_full_path_of (const char *filename, char **full_pathname) +source_full_path_of (const char *filename, size_t build_idsz, const gdb_byte *build_id, char **full_pathname) { int fd; fd = openp (source_path, OPF_TRY_CWD_FIRST | OPF_SEARCH_IN_PATH, - filename, full_pathname); + filename, build_idsz, build_id, full_pathname); if (fd < 0) { *full_pathname = NULL; @@ -1360,7 +1360,7 @@ find_and_open_source (const char *filename, } gdb_assert (OPEN_MODE == (O_RDONLY | O_BINARY)); - result = openp (path, OPF_SEARCH_IN_PATH, filename, fullname); + result = openp (path, OPF_SEARCH_IN_PATH, filename, 0 /* build_idsz */, NULL /* build_id */, fullname); if (result < 0) { /* Didn't work. Try using just the basename. */ @@ -1368,7 +1368,7 @@ find_and_open_source (const char *filename, if (p != filename) { gdb_assert (OPEN_MODE == (O_RDONLY | O_BINARY)); - result = openp (path, OPF_SEARCH_IN_PATH, p, fullname); + result = openp (path, OPF_SEARCH_IN_PATH, p, 0 /* build_idsz */, NULL /* build_id */, fullname); } } diff --git a/gdb/testsuite/gdb.base/attach.exp b/gdb/testsuite/gdb.base/attach.exp index bf0d84e..a879e33 100644 --- a/gdb/testsuite/gdb.base/attach.exp +++ b/gdb/testsuite/gdb.base/attach.exp @@ -67,7 +67,7 @@ proc do_attach_tests {} { global timeout # Figure out a regular expression that will match the sysroot, - # noting that the default sysroot is "target:", and also noting + # noting that the default sysroot is ":target:", and also noting # that GDB will strip "target:" from the start of filenames when # operating on the local filesystem set sysroot "" @@ -77,7 +77,10 @@ proc do_attach_tests {} { set sysroot $expect_out(1,string) } } - regsub "^target:" "$sysroot" "(target:)?" sysroot + # Use only the first element of $sysroot which will hopefully + # successfully match the filename. + regsub "^target:(\[^:\]*):.*$" "$sysroot" "" sysroot + regsub "^(?!target:)(\[^:\]*):.*$" "$sysroot" "" sysroot # Start the program running and then wait for a bit, to be sure # that it can be attached to. diff --git a/gdb/testsuite/gdb.base/main-mismatch-mod.c b/gdb/testsuite/gdb.base/main-mismatch-mod.c new file mode 100644 index 0000000..83d0710 --- /dev/null +++ b/gdb/testsuite/gdb.base/main-mismatch-mod.c @@ -0,0 +1,39 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2015 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + 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, see . */ + +#include + +int _bar = 21; + +int +bar (void) +{ + return 42 - _bar; +} + +int +foo (void) +{ + return 24 + bar(); +} + +int +main (void) +{ + sleep (60); + return 0; +} diff --git a/gdb/testsuite/gdb.base/main-mismatch.c b/gdb/testsuite/gdb.base/main-mismatch.c new file mode 100644 index 0000000..8ea17dc --- /dev/null +++ b/gdb/testsuite/gdb.base/main-mismatch.c @@ -0,0 +1,39 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2015 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + 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, see . */ + +#include + +int _bar = 42; + +int +bar (void) +{ + return _bar + 21; +} + +int +foo (void) +{ + return _bar; +} + +int +main (void) +{ + sleep (60); + return 0; +} diff --git a/gdb/testsuite/gdb.base/main-mismatch.exp b/gdb/testsuite/gdb.base/main-mismatch.exp new file mode 100644 index 0000000..3a5e18d --- /dev/null +++ b/gdb/testsuite/gdb.base/main-mismatch.exp @@ -0,0 +1,178 @@ +# Copyright 2015 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# 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, see . */ + +standard_testfile + +if ![is_remote target] { + untested "only gdbserver supports build-id reporting" +#FIXME: +### return -1 +} +if [is_remote host] { + untested "only local host is currently supported" + return -1 +} + +# Test overview: +# generate two executable. One that will be used by the process +# and another, modified, that will be found by gdb. Gdb should +# detect the mismatch and refuse to use mismatched executable. + +if { [get_compiler_info] } { + untested "get_compiler_info failed." + return -1 +} + +# First version of the object, to be loaded by ld. +set srcmainfilerun ${testfile}.c + +# Modified version of the object to be loaded by gdb +# Code in -libmod.c is tuned so it gives a mismatch but +# leaves .dynamic at the same point. +set srcmainfilegdb ${testfile}-mod.c + +# So file name: +set binmainfilebase {testfile} + +# Setup run directory (where program is run from) +# It contains the right executable. +set binmainfiledirrun [standard_output_file ${testfile}_wd] +set binmainfilerun ${binmainfiledirrun}/${binmainfilebase} + +# Second executable version is in current directory, '-mod' version. +set binmainfiledirgdb [standard_output_file ""] +set binmainfilegdb ${binmainfiledirgdb}/${binmainfilebase} + +file delete -force -- "${binmainfiledirrun}" +file mkdir "${binmainfiledirrun}" + +set exec_opts {} +lappend exec_opts "additional_flags=-DDIRNAME\=\"${binmainfiledirrun}\"" +lappend exec_opts "debug" +lappend exec_opts "ldflags=-Wl,--build-id" + +if { [build_executable $testfile.exp $binmainfilerun $srcmainfilerun $exec_opts] != 0 } { + return -1 +} +if { [build_executable $testfile.exp $binmainfilegdb $srcmainfilegdb $exec_opts] != 0 } { + return -1 +} + +proc main_matching_test { symsloaded } { + global gdb_prompt + global binmainfilerun + + clean_restart + + set test_spawn_id [spawn_wait_for_attach $binmainfilerun] + set testpid [spawn_id_get_pid $test_spawn_id] + + set test "attach" + gdb_test_multiple "attach $testpid" "$test" { + -re "Attaching to program.*\r\n$gdb_prompt $" { + pass "$test" + } + } + + if { $symsloaded } { + gdb_test "bt" " in main \[^\r\n\]*" + } else { + set test "bt" + gdb_test_multiple $test $test { + -re " in main \[^\r\n\]*\r\n$gdb_prompt $" { + fail $test + } + -re "\r\n$gdb_prompt $" { + pass $test + } + } + } + + kill_wait_spawned_process $test_spawn_id + + return 0 +} + +proc main_locate_test { solibfile symsloaded } { + global binmainfiledirrun + global binmainfilerun + global nocrlf + global expected_header + + gdb_test_no_output "set debug-file-directory ${binmainfiledirrun}" "" + gdb_test_no_output "nosharedlibrary" "" + gdb_test "sharedlibrary" "" "" + + set expected_line "${symsloaded}${nocrlf}${solibfile}" + + gdb_test "info sharedlibrary ${solibfile}" \ + "${expected_header}\r\n.*${expected_line}.*" \ + "Symbols for ${solibfile} loaded: expected '${symsloaded}'" +} + +# Copy binary to working dir so it pulls in the library from that dir +# (by the virtue of $ORIGIN). +file copy -force "${binmainfiledirgdb}/${binmainfilebase}" \ + "${binmainfiledirrun}/${binmainfilebase}" + +# Test unstripped, .dynamic matching +with_test_prefix "test unstripped, .dynamic matching" { + main_matching_test 0 +} + +# Keep original so for debugging purposes +file copy -force "${binmainfilegdb}" "${binmainfilegdb}-orig" +set objcopy_program [transform objcopy] +set result [catch "exec $objcopy_program --only-keep-debug ${binmainfilegdb}"] hooks/post-receive -- Repository for Project Archer.