summaryrefslogtreecommitdiffstats
path: root/gdb
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2009-12-14 13:07:19 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2009-12-14 13:07:19 +0000
commitd812496da776750491db0e37f2ba481ae9d0012a (patch)
treed32a619e494e482ec17044f64795df52f76a1dee /gdb
parent2009-12-10 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-examples-d812496da776750491db0e37f2ba481ae9d0012a.tar.bz2
2009-12-14 Joel Sherrill <joel.sherrill@oarcorp.com>
* ChangeLog, overwrite/.cvsignore, overwrite/Makefile, overwrite/README, overwrite/overwrite.c, overwrite/rtems_init.c: New files.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog6
-rw-r--r--gdb/overwrite/.cvsignore2
-rw-r--r--gdb/overwrite/Makefile27
-rw-r--r--gdb/overwrite/README8
-rw-r--r--gdb/overwrite/overwrite.c61
-rw-r--r--gdb/overwrite/rtems_init.c32
6 files changed, 136 insertions, 0 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
new file mode 100644
index 0000000..f2a9d5e
--- /dev/null
+++ b/gdb/ChangeLog
@@ -0,0 +1,6 @@
+2009-12-14 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * ChangeLog, overwrite/.cvsignore, overwrite/Makefile,
+ overwrite/README, overwrite/overwrite.c, overwrite/rtems_init.c:
+ New files.
+
diff --git a/gdb/overwrite/.cvsignore b/gdb/overwrite/.cvsignore
new file mode 100644
index 0000000..c378ba0
--- /dev/null
+++ b/gdb/overwrite/.cvsignore
@@ -0,0 +1,2 @@
+o-optimize
+overwrite
diff --git a/gdb/overwrite/Makefile b/gdb/overwrite/Makefile
new file mode 100644
index 0000000..f74a91c
--- /dev/null
+++ b/gdb/overwrite/Makefile
@@ -0,0 +1,27 @@
+#
+# $Id$
+#
+
+#
+# RTEMS_MAKEFILE_PATH is typically set in an environment variable
+#
+
+PGM=${ARCH}/overwrite.exe
+
+# optional managers required
+MANAGERS=all
+
+# C source names
+CSRCS = overwrite.c rtems_init.c
+COBJS = $(CSRCS:%.c=${ARCH}/%.o)
+
+include $(RTEMS_MAKEFILE_PATH)/Makefile.inc
+include $(RTEMS_CUSTOM)
+include $(PROJECT_ROOT)/make/leaf.cfg
+
+OBJS= $(COBJS) $(CXXOBJS) $(ASOBJS)
+
+all: ${ARCH} $(PGM)
+
+$(PGM): $(OBJS)
+ $(make-exe)
diff --git a/gdb/overwrite/README b/gdb/overwrite/README
new file mode 100644
index 0000000..931214c
--- /dev/null
+++ b/gdb/overwrite/README
@@ -0,0 +1,8 @@
+#
+# $Id$
+#
+
+This program deliberately writes past the end of an array and
+corrupts another variable. This is done so the program can
+be used to demonstrate how the gdb "watch" command can be used
+to track down this type of programming error.
diff --git a/gdb/overwrite/overwrite.c b/gdb/overwrite/overwrite.c
new file mode 100644
index 0000000..98b119f
--- /dev/null
+++ b/gdb/overwrite/overwrite.c
@@ -0,0 +1,61 @@
+/*
+ * Simple test program to demonstrate memory overwrite.
+ *
+ * $Id$
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+
+typedef struct {
+ uint32_t TooShortArray[8];
+ uint32_t RandomVariable;
+ uint32_t CorruptedVariable;
+} Struct_t;
+
+Struct_t S;
+
+void writeEntry(int index, uint32_t value);
+
+int main(
+ int argc,
+ char **argv
+)
+{
+ puts( "\n\n*** MEMORY CORRUPTION EXAMPLE ***" );
+
+ /* initialize global variables */
+ memset( &S, 0, sizeof(S) );
+ S.RandomVariable = 0x1234;
+ S.CorruptedVariable = 0x5678;
+
+ printf(
+ "&TooShortArray[0] = %p\n"
+ "&TooShortArray[7] = %p\n"
+ "&RandomVariable = %p\n"
+ "&CorruptedVariable = %p\n",
+ &S.TooShortArray[0],
+ &S.TooShortArray[7],
+ &S.RandomVariable,
+ &S.CorruptedVariable
+ );
+ /* write past end of array */
+ writeEntry( 8, 0xdeadf00d );
+ writeEntry( 9, 0x0badd00d );
+
+ printf(
+ "RandomVariable = 0x%08x\n"
+ "CorruptedVariable = 0x%08x\n",
+ S.RandomVariable,
+ S.CorruptedVariable
+ );
+ puts( "*** END OF MEMORY CORRUPTION EXAMPLE ***" );
+ exit( 0 );
+}
+
+void writeEntry(int index, uint32_t value)
+{
+ S.TooShortArray[index] = value;
+}
diff --git a/gdb/overwrite/rtems_init.c b/gdb/overwrite/rtems_init.c
new file mode 100644
index 0000000..2753d7f
--- /dev/null
+++ b/gdb/overwrite/rtems_init.c
@@ -0,0 +1,32 @@
+/*
+ * Wrapper for Overwrite main().
+ *
+ * $Id$
+ */
+
+#include <bsp.h>
+
+int main( int, char ** );
+
+rtems_task Init(
+ rtems_task_argument ignored
+)
+{
+ main( 0, NULL );
+ exit( 0 ); /* just in case */
+}
+
+/* configuration information */
+
+/* NOTICE: the clock driver is explicitly disabled */
+#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+#define CONFIGURE_MAXIMUM_TASKS 1
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
+
+/* end of file */