From patchwork Wed Dec 4 02:36:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gabriel F. T. Gomes" X-Patchwork-Id: 36490 Received: (qmail 39019 invoked by alias); 4 Dec 2019 02:36:54 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 38603 invoked by uid 89); 4 Dec 2019 02:36:54 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=letting, H*F:D*br X-HELO: smtpout1.mo803.mail-out.ovh.net From: "Gabriel F. T. Gomes" To: CC: Subject: [PATCH 2/2] Do not use ld.so to open statically linked programs in debugglibc.sh Date: Tue, 3 Dec 2019 23:36:31 -0300 Message-ID: <20191204023631.29512-3-gabriel@inconstante.net.br> In-Reply-To: <20191204023631.29512-1-gabriel@inconstante.net.br> References: <20191204023631.29512-1-gabriel@inconstante.net.br> MIME-Version: 1.0 X-Ovh-Tracer-Id: 2000161187844378307 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedufedrudejkedggeejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdqfffguegfifdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvffufffkofgjfhgggfgtihesthekredtredttdenucfhrhhomhepfdfirggsrhhivghlucfhrdcuvfdrucfiohhmvghsfdcuoehgrggsrhhivghlsehinhgtohhnshhtrghnthgvrdhnvghtrdgsrheqnecukfhppedtrddtrddtrddtpddujeejrddukedrudelkedrudejheenucfrrghrrghmpehmohguvgepshhmthhpqdhouhhtpdhhvghlohepgfgigedrvghmphdrlhhotggrlhdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomhepghgrsghrihgvlhesihhntghonhhsthgrnhhtvgdrvghtihdrsghrpdhrtghpthhtoheptggrrhhlohhssehrvgguhhgrthdrtghomhenucevlhhushhtvghrufhiiigvpedt From: "Gabriel F. T. Gomes" Debugging programs that have been dynamically linked against an uninstalled glibc requires unusual steps, such as letting gdb know where the thread db library is located and explicitly calling the loader. However, when the program under test is statically linked, these steps are not required (as a matter of fact, using the dynamic loader to run a statically linked program is wrong and will fail), and gdb should be called the usual way. This patch modifies debugglibc.sh so that it checks if the program under test is statically linked, then runs the debugger appropriately. Reviewed-by: Carlos O'Donell --- Makefile | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 924fdb6c0f..b43226c35a 100644 --- a/Makefile +++ b/Makefile @@ -209,6 +209,7 @@ BUILD_DIR="$(common-objpfx)" CMD_FILE="$(common-objpfx)debugglibc.gdb" CONTAINER=false DIRECT=true +STATIC=false SYMBOLSFILE=true unset TESTCASE unset BREAKPOINTS @@ -297,8 +298,8 @@ do shift done -# Check for required argument -if [ ! -v TESTCASE ] +# Check for required argument and if the testcase exists +if [ ! -v TESTCASE ] || [ ! -f $${TESTCASE} ] then usage exit 1 @@ -318,6 +319,14 @@ else DIRECT="" fi +# Check if the test case is static +if file $${TESTCASE} | grep "statically linked" >/dev/null +then + STATIC=true +else + STATIC=false +fi + # Expand symbols loading command if [ "$$SYMBOLSFILE" == true ] then @@ -366,6 +375,9 @@ then # automatically attach GDB to it. WAIT_FOR_DEBUGGER=1 $(common-objpfx)testrun.sh --tool=container $${TESTCASE} & gdb -x $${TESTCASE}.gdb +elif [ "$$STATIC" == true ] +then +gdb $${TESTCASE} else # Start the test case debugging in two steps: # 1. the following command invokes gdb to run the loader;