[bootlin/training-materials updates] master: debugging: lab-data: fix wrong valgrind commands (c6e9e8ec)

Clément Léger clement.leger at bootlin.com
Wed Nov 23 10:02:05 CET 2022


Repository : https://github.com/bootlin/training-materials
On branch  : master
Link       : https://github.com/bootlin/training-materials/commit/c6e9e8ecba985733288856b744ed21ee58b3373d

>---------------------------------------------------------------

commit c6e9e8ecba985733288856b744ed21ee58b3373d
Author: Clément Léger <clement.leger at bootlin.com>
Date:   Wed Nov 23 09:13:58 2022 +0100

    debugging: lab-data: fix wrong valgrind commands
    
    Signed-off-by: Clément Léger <clement.leger at bootlin.com>


>---------------------------------------------------------------

c6e9e8ecba985733288856b744ed21ee58b3373d
 .../debugging/nfsroot/root/valgrind/valgrind.c     | 54 ++++++++++++++++++++++
 .../debugging/nfsroot/root/valgrind/vallgrind.c    | 54 ----------------------
 .../debugging-memory-issues.tex                    | 10 ++--
 3 files changed, 59 insertions(+), 59 deletions(-)

diff --git a/lab-data/debugging/nfsroot/root/valgrind/valgrind.c b/lab-data/debugging/nfsroot/root/valgrind/valgrind.c
new file mode 100644
index 00000000..1acdf3e2
--- /dev/null
+++ b/lab-data/debugging/nfsroot/root/valgrind/valgrind.c
@@ -0,0 +1,54 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+static int *allocate_array(int size)
+{
+	return malloc(size * sizeof(int));
+}
+
+static int clear_array(int *p, int size)
+{
+	int i;
+
+	for (i = 0; i <= size; i++)
+		p[i] = 0;
+}
+
+static void write_file(int *p, int size)
+{
+	int fd;
+
+	fd = creat("/tmp/seq", S_IRWXU);
+	if (fd < 0)
+		return;
+
+	write(fd, p, size * sizeof(int));
+	close(fd);
+}
+
+static void fill_sequential(int *p, int size)
+{
+	int i;
+
+	for (i = 0; i < size - 1; i++)
+		p[i] = i;
+}
+
+static void do_something(int size)
+{
+	int *p = allocate_array(size);
+	if (!p)
+		return;
+
+	fill_sequential(p, size);
+	write_file(p, size);
+	clear_array(p, size);
+}
+
+int main(void)
+{
+	do_something(100);
+	do_something(200);
+}
\ No newline at end of file
diff --git a/lab-data/debugging/nfsroot/root/valgrind/vallgrind.c b/lab-data/debugging/nfsroot/root/valgrind/vallgrind.c
deleted file mode 100644
index 1acdf3e2..00000000
--- a/lab-data/debugging/nfsroot/root/valgrind/vallgrind.c
+++ /dev/null
@@ -1,54 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-static int *allocate_array(int size)
-{
-	return malloc(size * sizeof(int));
-}
-
-static int clear_array(int *p, int size)
-{
-	int i;
-
-	for (i = 0; i <= size; i++)
-		p[i] = 0;
-}
-
-static void write_file(int *p, int size)
-{
-	int fd;
-
-	fd = creat("/tmp/seq", S_IRWXU);
-	if (fd < 0)
-		return;
-
-	write(fd, p, size * sizeof(int));
-	close(fd);
-}
-
-static void fill_sequential(int *p, int size)
-{
-	int i;
-
-	for (i = 0; i < size - 1; i++)
-		p[i] = i;
-}
-
-static void do_something(int size)
-{
-	int *p = allocate_array(size);
-	if (!p)
-		return;
-
-	fill_sequential(p, size);
-	write_file(p, size);
-	clear_array(p, size);
-}
-
-int main(void)
-{
-	do_something(100);
-	do_something(200);
-}
\ No newline at end of file
diff --git a/labs/debugging-memory-issues/debugging-memory-issues.tex b/labs/debugging-memory-issues/debugging-memory-issues.tex
index 64fb3084..9344cb8a 100644
--- a/labs/debugging-memory-issues/debugging-memory-issues.tex
+++ b/labs/debugging-memory-issues/debugging-memory-issues.tex
@@ -14,7 +14,7 @@ information using:
 
 \begin{bashinput}
 $ cd /home/<user>/debugging-labs/nfsroot/root/valgrind
-$ ${CROSS_COMPILE}-gcc -g3 valgrind.c -o test_valgrind
+$ make
 \end{bashinput}
 
 Then run it on the target. Do you notice any problem ? Does it run correctly ?
@@ -24,7 +24,7 @@ or even out-of-bounds accesses, uninitialized memory, etc.
 Now, run the command again with valgrind using the following command:
 
 \begin{bashinput}
-$ valgrind --leak-check=full ./test_valgrind
+$ valgrind --leak-check=full ./valgrind
 \end{bashinput}
 
 You'll see various errors found by valgrind
@@ -40,7 +40,7 @@ need to run valgrind with vgdb enabled on the target:
 
 \begin{bashinput}
 $ cd /root/valgrind
-$ valgrind --vgdb-error=0 --leak-check=full ./test_valgrind
+$ valgrind --vgdb-error=0 --leak-check=full ./valgrind
 \end{bashinput}
 
 Then, in order to do remote debugging, we also need to run vgdb in listen mode.
@@ -50,10 +50,10 @@ Start another terminal in SSH on the target and run the following command:
 $ vgdb --port=1234
 \end{bashinput}
 
-On the computer side, start gdb-multiarch and give it the \code{test_valgrind}
+On the computer side, start gdb-multiarch and give it the \code{valgrind}
 binary which will allow to detect the architecture and read symbols:
 \begin{bashinput}
-$ gdb-multiarch ./test_valgrind
+$ gdb-multiarch ./valgrind
 \end{bashinput}
 
 Finally, we'll need to connect to vgdb using the following gdb command:




More information about the training-materials-updates mailing list