[2/2] Do not use ld.so to open statically linked programs in debugglibc.sh
diff mbox series

Message ID 20191204023631.29512-3-gabriel@inconstante.net.br
State New
Headers show
Series
  • New options for debugglibc.sh and testrun.sh
Related show

Commit Message

Gabriel F. T. Gomes Dec. 4, 2019, 2:36 a.m. UTC
From: "Gabriel F. T. Gomes" <gabrielftg@linux.ibm.com>

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.
---
 Makefile | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

Comments

Carlos O'Donell Dec. 4, 2019, 2:44 a.m. UTC | #1
On 12/3/19 9:36 PM, Gabriel F. T. Gomes wrote:
> From: "Gabriel F. T. Gomes" <gabrielftg@linux.ibm.com>
> 
> 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.

We still need to inform gdb where the libthread_db.so is though?

This is better than what we have and helps. I think having
this code in place means people can use it and it works, even if we have
slight problems we'll iron them out as we use it.

OK for master. 

Reviewed-by: Carlos O'Donell <carlos@redhat.com>

> This patch modifies debugglibc.sh so that it checks if the program under
> test is statically linked, then runs the debugger appropriately.
> ---
>  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

OK.

>  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} ]

OK.

>  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

OK. Detect with `file` which is good enough.

> +
>  # 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}

OK. This is better than anything, but we might need more to make threads in
static binaries work properly.

>  else
>  # Start the test case debugging in two steps:
>  #   1. the following command invokes gdb to run the loader;
>

Patch
diff mbox series

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;