From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18628 invoked by alias); 15 Oct 2013 14:21:17 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 18545 invoked by uid 89); 15 Oct 2013 14:21:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.0 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 15 Oct 2013 14:21:13 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1VW5Ui-0007FE-R6 from Maciej_Rozycki@mentor.com for gdb-patches@sourceware.org; Tue, 15 Oct 2013 07:21:08 -0700 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Tue, 15 Oct 2013 07:21:06 -0700 Received: from [172.30.64.75] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.2.247.3; Tue, 15 Oct 2013 15:21:04 +0100 Date: Tue, 15 Oct 2013 14:21:00 -0000 From: "Maciej W. Rozycki" To: Subject: [PATCH] Avoid producing broken non-native core files Message-ID: User-Agent: Alpine 1.10 (DEB 962 2008-03-14) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-SW-Source: 2013-10/txt/msg00456.txt.bz2 Hi, We don't have complete non-native core file generation support across all the supported targets. We have explicit support for some targets that is implemented differently depending on how general core file support has been wired in for a given target, either in GDB proper (the old scheme, such as with mips-linux-gnu) or in BFD (the new scheme, such as with i686-linux-gnu). Unfortunately where non-native core file support is missing the results are inconsistent between the two cases. The two paths diverge in linux_make_corefile_notes_1, the old defaults to exec_make_note_section and fails mostly gracefully (an unfinished dump is left behind). The new path does not fail, but an incomplete dump is produced with no register information, that GDB itself does not handle ('"foo" is not a core dump: File format not recognized') and that scores a number of failures in the test suite across various cases, e.g.: (gdb) PASS: gdb.base/auxv.exp: continue info auxv 32 AT_SYSINFO Special system info/entry points 0xb7fdd400 33 AT_SYSINFO_EHDR System-supplied DSO's ELF header 0xb7fdd000 16 AT_HWCAP Machine-dependent CPU capability hints 0xbfe9fbf7 6 AT_PAGESZ System page size 4096 17 AT_CLKTCK Frequency of times() 100 3 AT_PHDR Program headers for program 0x8048034 4 AT_PHENT Size of program header entry 32 5 AT_PHNUM Number of program headers 8 7 AT_BASE Base address of interpreter 0xb7fde000 8 AT_FLAGS Flags 0x0 9 AT_ENTRY Entry point of program 0x8048590 11 AT_UID Real user ID 49869 12 AT_EUID Effective user ID 49869 13 AT_GID Real group ID 280 14 AT_EGID Effective group ID 280 23 AT_SECURE Boolean, was exec setuid-like? 0 15 AT_PLATFORM String identifying platform 0xbffff9cb "i686" 0 AT_NULL End of vector 0x0 (gdb) PASS: gdb.base/auxv.exp: info auxv on live process gcore .../gdb.base/auxv.gcore Saved corefile .../gdb.base/auxv.gcore (gdb) PASS: gdb.base/auxv.exp: gcore continue Continuing. Program received signal SIGABRT, Aborted. 0xb7fdd410 in __kernel_vsyscall () (gdb) PASS: gdb.base/auxv.exp: continue continue Continuing. Program terminated with signal SIGABRT, Aborted. The program no longer exists. (gdb) PASS: gdb.base/auxv.exp: continue UNSUPPORTED: gdb.base/auxv.exp: generate native core dump Executing on build: rm -rf .../gdb.base/coredir.4310 (timeout = 3000) Child terminated with signal = 0x6 (SIGABRT) GDBserver exiting UNSUPPORTED: gdb.base/auxv.exp: info auxv on native core dump UNSUPPORTED: gdb.base/auxv.exp: matching auxv data from live and core core .../gdb.base/auxv.gcore ".../gdb.base/auxv.gcore" is not a core dump: File format not recognized (gdb) FAIL: gdb.base/auxv.exp: load core file for info auxv on gcore-created dump info auxv The program has no auxiliary information now. (gdb) FAIL: gdb.base/auxv.exp: info auxv on gcore-created dump FAIL: gdb.base/auxv.exp: matching auxv data from live and gcore testcase .../gdb/testsuite/gdb.base/auxv.exp completed in 3 seconds === gdb Summary === # of expected passes 8 # of unexpected failures 3 # of unsupported tests 3 The cause of missing register information is elfcore_write_prstatus in BFD that writes no data (and returns NULL) on non-native targets that have no explicit support (bed->elf_backend_write_core_note is NULL), because HAVE_PRSTATUS_T and HAVE_PRSTATUS32_T are both forcibly undefined for non-native BFD configurations. Given that such core files produced are useless anyway I propose that for targets where elfcore_write_prstatus is indeed used and returns NULL an error message was printed and core file preparation aborted. This is implemented in linux_corefile_thread_callback where signal information is also stored and currently overwrites any unsuccessful return status from the register store worker function (linux_collect_thread_registers). The test framework is updated accordingly to handle the alternative error message produced in that case. This change removes the failure shown above: (gdb) PASS: gdb.base/auxv.exp: continue info auxv 32 AT_SYSINFO Special system info/entry points 0xb7fdd400 33 AT_SYSINFO_EHDR System-supplied DSO's ELF header 0xb7fdd000 16 AT_HWCAP Machine-dependent CPU capability hints 0xbfe9fbf7 6 AT_PAGESZ System page size 4096 17 AT_CLKTCK Frequency of times() 100 3 AT_PHDR Program headers for program 0x8048034 4 AT_PHENT Size of program header entry 32 5 AT_PHNUM Number of program headers 8 7 AT_BASE Base address of interpreter 0xb7fde000 8 AT_FLAGS Flags 0x0 9 AT_ENTRY Entry point of program 0x8048590 11 AT_UID Real user ID 49869 12 AT_EUID Effective user ID 49869 13 AT_GID Real group ID 280 14 AT_EGID Effective group ID 280 23 AT_SECURE Boolean, was exec setuid-like? 0 15 AT_PLATFORM String identifying platform 0xbffff9cb "i686" 0 AT_NULL End of vector 0x0 (gdb) PASS: gdb.base/auxv.exp: info auxv on live process gcore .../gdb.base/auxv.gcore Target does not support core file generation. (gdb) UNSUPPORTED: gdb.base/auxv.exp: gcore continue Continuing. Program received signal SIGABRT, Aborted. 0xb7fdd410 in __kernel_vsyscall () (gdb) PASS: gdb.base/auxv.exp: continue continue Continuing. Program terminated with signal SIGABRT, Aborted. The program no longer exists. (gdb) PASS: gdb.base/auxv.exp: continue UNSUPPORTED: gdb.base/auxv.exp: generate native core dump Executing on build: rm -rf .../gdb.base/coredir.5217 (timeout = 3000) Child terminated with signal = 0x6 (SIGABRT) GDBserver exiting UNSUPPORTED: gdb.base/auxv.exp: info auxv on native core dump UNSUPPORTED: gdb.base/auxv.exp: matching auxv data from live and core UNSUPPORTED: gdb.base/auxv.exp: info auxv on gcore-created dump UNSUPPORTED: gdb.base/auxv.exp: matching auxv data from live and gcore testcase .../gdb/testsuite/gdb.base/auxv.exp completed in 1 seconds === gdb Summary === # of expected passes 7 # of unsupported tests 6 -- tested with the i686-linux-gnu target. OK to apply? 2013-10-15 Maciej W. Rozycki gdb/ * linux-tdep.c (linux_corefile_thread_callback): Propagate any failure from register information collection. gdb/testsuite/ * lib/gdb.exp (gdb_gcore_cmd): Also handle a "Target does not support core file generation" reply. Maciej gdb-core-note-data.diff Index: gdb-fsf-trunk-quilt/gdb/linux-tdep.c =================================================================== --- gdb-fsf-trunk-quilt.orig/gdb/linux-tdep.c 2013-10-14 22:44:49.868756722 +0100 +++ gdb-fsf-trunk-quilt/gdb/linux-tdep.c 2013-10-14 22:46:21.887601484 +0100 @@ -1211,7 +1211,9 @@ linux_corefile_thread_callback (struct t args->stop_signal); args->num_notes++; - if (siginfo_data != NULL) + /* Don't return anything if we got no register information above, + such a core file is useless. */ + if (args->note_data != NULL && siginfo_data != NULL) { args->note_data = elfcore_write_note (args->obfd, args->note_data, Index: gdb-fsf-trunk-quilt/gdb/testsuite/lib/gdb.exp =================================================================== --- gdb-fsf-trunk-quilt.orig/gdb/testsuite/lib/gdb.exp 2013-10-14 22:44:44.867662030 +0100 +++ gdb-fsf-trunk-quilt/gdb/testsuite/lib/gdb.exp 2013-10-14 22:46:21.887601484 +0100 @@ -3183,7 +3183,7 @@ proc gdb_gcore_cmd {core test} { verbose -log "'gcore' command undefined in gdb_gcore_cmd" } - -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" { + -re "(?:Can't create a corefile|Target does not support core file generation\\.)\[\r\n\]+$gdb_prompt $" { unsupported $test } }