[bootlin/training-materials updates] master: debugging: labs: rename valgrind lab binary to avoid confusion with valgrind tool binary (cbc2e39c)
Alexis Lothoré
alexis.lothore at bootlin.com
Wed Jul 5 09:12:03 CEST 2023
Repository : https://github.com/bootlin/training-materials
On branch : master
Link : https://github.com/bootlin/training-materials/commit/cbc2e39cd3412f74b0fb9afe690b373eb50d1830
>---------------------------------------------------------------
commit cbc2e39cd3412f74b0fb9afe690b373eb50d1830
Author: Alexis Lothoré <alexis.lothore at bootlin.com>
Date: Fri Apr 21 09:49:22 2023 +0200
debugging: labs: rename valgrind lab binary to avoid confusion with valgrind tool binary
>---------------------------------------------------------------
cbc2e39cd3412f74b0fb9afe690b373eb50d1830
lab-data/debugging/nfsroot/root/valgrind/Makefile | 2 +-
.../nfsroot/root/valgrind/faulty_mem_app.c | 54 ++++++++++++++++++++++
.../debugging/nfsroot/root/valgrind/valgrind.c | 54 ----------------------
.../debugging-memory-issues.tex | 8 ++--
4 files changed, 59 insertions(+), 59 deletions(-)
diff --git a/lab-data/debugging/nfsroot/root/valgrind/Makefile b/lab-data/debugging/nfsroot/root/valgrind/Makefile
index 1d44db68..0585c9fc 100644
--- a/lab-data/debugging/nfsroot/root/valgrind/Makefile
+++ b/lab-data/debugging/nfsroot/root/valgrind/Makefile
@@ -1,4 +1,4 @@
CC=${CROSS_COMPILE}gcc
-valgrind: valgrind.c
+faulty_mem_app: faulty_mem_app.c
${CC} $< -g3 -o $@
diff --git a/lab-data/debugging/nfsroot/root/valgrind/faulty_mem_app.c b/lab-data/debugging/nfsroot/root/valgrind/faulty_mem_app.c
new file mode 100644
index 00000000..1acdf3e2
--- /dev/null
+++ b/lab-data/debugging/nfsroot/root/valgrind/faulty_mem_app.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/valgrind.c b/lab-data/debugging/nfsroot/root/valgrind/valgrind.c
deleted file mode 100644
index 1acdf3e2..00000000
--- a/lab-data/debugging/nfsroot/root/valgrind/valgrind.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 6b35873c..bd234276 100644
--- a/labs/debugging-memory-issues/debugging-memory-issues.tex
+++ b/labs/debugging-memory-issues/debugging-memory-issues.tex
@@ -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 ./valgrind
+$ valgrind --leak-check=full ./faulty_mem_app
\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 ./valgrind
+$ valgrind --vgdb-error=0 --leak-check=full ./faulty_mem_app
\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{valgrind}
+On the computer side, start gdb-multiarch and give it the \code{faulty_mem_app}
binary which will allow to detect the architecture and read symbols:
\begin{bashinput}
-$ gdb-multiarch ./valgrind
+$ gdb-multiarch ./faulty_mem_app
\end{bashinput}
Finally, we'll need to connect to vgdb using the following gdb command:
More information about the training-materials-updates
mailing list