From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EDAC23858C39; Fri, 10 Sep 2021 11:55:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EDAC23858C39 From: "patrickdepinguin at gmail dot com" To: gdb-prs@sourceware.org Subject: [Bug gdb/28330] New: gdbinit file should be loaded before core file Date: Fri, 10 Sep 2021 11:55:44 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: gdb X-Bugzilla-Version: 9.2 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: patrickdepinguin at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gdb-prs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-prs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Sep 2021 11:55:45 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D28330 Bug ID: 28330 Summary: gdbinit file should be loaded before core file Product: gdb Version: 9.2 Status: UNCONFIRMED Severity: normal Priority: P2 Component: gdb Assignee: unassigned at sourceware dot org Reporter: patrickdepinguin at gmail dot com Target Milestone: --- In a cross-compilation context, gdb will not be able to load all shared libraries without additional information like a sysroot. Such context-speci= fic settings can be passed via gdbinit files specified on the gdb command-line = via '-x' (--command). Buildroot (a tool to help build images for embedded Linux), for example, wi= ll create a gdbinit file that sets the right sysroot ('set sysroot'). However, the gdbinit file(s) passed on the gdb command-line are currently r= ead _after_ the core file, which leads to a large number of warning messages, w= hich is very confusing to unwary users: $ cross-gdb myapp mycorefile GNU gdb (GDB) 9.2 Copyright (C) 2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=3Dx86_64-pc-linux-gnu --target=3Di686-buildroot-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from myapp... warning: core file may not match specified executable file. [New LWP 602] [New LWP 8307] warning: .dynamic section for "/lib/libstdc++.so.6" is not at the expected address (wrong library or version mismatch?) warning: .dynamic section for "/lib/librt.so.1" is not at the expected addr= ess (wrong library or version mismatch?) warning: .dynamic section for "/lib/libm.so.6" is not at the expected addre= ss (wrong library or version mismatch?) warning: .dynamic section for "/lib/libgcc_s.so.1" is not at the expected address (wrong library or version mismatch?) warning: .dynamic section for "/lib/libc.so.6" is not at the expected addre= ss (wrong library or version mismatch?) warning: .dynamic section for "/lib/ld-linux.so.2" is not at the expected address (wrong library or version mismatch?) warning: .dynamic section for "/lib/libanl.so.1" is not at the expected add= ress (wrong library or version mismatch?) warning: .dynamic section for "/lib/libdl.so.2" is not at the expected addr= ess (wrong library or version mismatch?) warning: .dynamic section for "/lib/libpthread.so.0" is not at the expected address (wrong library or version mismatch?) warning: .dynamic section for "/usr/lib/libz.so.1" is not at the expected address (wrong library or version mismatch?) warning: .dynamic section for "/lib/libnss_files.so.2" is not at the expect= ed address (wrong library or version mismatch?) warning: Could not load shared library symbols for 17 libraries, e.g. [...] Use the "info sharedlibrary" command to see the complete listing. Do you need "set solib-search-path" or "set sysroot"? Core was generated by `myapp args'. Program terminated with signal SIGSEGV, Segmentation fault. #0 0xf7fd3a29 in __kernel_vsyscall () [Current thread is 1 (LWP 602)] show warning: File ".../i686-buildroot-linux-gnu/sysroot/lib/libstdc++.so.6.0.24-gdb.py" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load". To enable execution of this file add add-auto-load-safe-path .../i686-buildroot-linux-gnu/sysroot/lib/libstdc++.so.6.0.24-gdb.py line to your configuration file "/home/me/.gdbinit". To completely disable this security protection add set auto-load safe-path / line to your configuration file "/home/me/.gdbinit". For more information about this security protection see the "Auto-loading safe path" section in the GDB manual. E.g., run from the she= ll: info "(gdb)Auto-loading safe path" (gdb) When you check e.g. 'info shared' from the gdb prompt, all libraries are lo= aded correctly (thanks to the sysroot specified in gdbinit file), so these warni= ngs are actually invalid and confusing. With respect to the loading of the C++ pretty-printers, there is an actual problem caused by the core file being loaded before the gdbinit files: even though the 'auto-load-safe-path' was set to a correct value from the gdbinit files, the pretty-printer file 'libstdc++.so.6.0.24-gdb.py' file was _NOT_ loaded, because the 'auto-load-safe-path' at the time of loading the core f= ile did not _yet_ include the correct value, and this is not re-attempted at a later stage. (gdb) show auto-load safe-path=20 List of directories from which it is safe to auto-load files is $debugdir:$datadir/auto-load:[...]/i686-buildroot-linux-gnu/sysroot. (gdb) show sysroot The current system root is "[...]/i686-buildroot-linux-gnu/sysroot". (gdb) info pretty-printer global pretty-printers: builtin mpx_bound128 When I use the same gdb and gdbinit files without core file, connecting to = an actual target, the pretty printers are loaded correctly: (gdb) info pretty-printer global pretty-printers: builtin mpx_bound128 objfile [...]/i686-buildroot-linux-gnu/sysroot/lib/libstdc++.so.6 pretty-printers: libstdc++-v6 __gnu_cxx::_Slist_iterator __gnu_cxx::__7::_Slist_iterator __gnu_cxx::__7::__normal_iterator __gnu_cxx::__7::slist __gnu_cxx::__normal_iterator __gnu_cxx::slist [...] These problems would be fixed if the gdbinit files specified on the command-line were loaded before the core file is read. I read in the NEWS file that in gdb 4.6, a similar change was already done = for the $HOME/.gdbinit file, but _not_ for other gdbinit files. It is unclear t= o me what the reason is for this. --=20 You are receiving this mail because: You are on the CC list for the bug.=