From 7ed2af70f929587b6e45cb561ed93afcf4faf111 Mon Sep 17 00:00:00 2001 From: adamdunkels Date: Tue, 2 Feb 2010 15:28:52 +0000 Subject: [PATCH] Two 'peek' and 'poke' commands for reading and writing directly to memory --- apps/shell/Makefile.shell | 2 +- apps/shell/shell-memdebug.c | 129 ++++++++++++++++++++++++++++++++++++ apps/shell/shell-memdebug.h | 48 ++++++++++++++ apps/shell/shell.h | 3 +- 4 files changed, 180 insertions(+), 2 deletions(-) create mode 100644 apps/shell/shell-memdebug.c create mode 100644 apps/shell/shell-memdebug.h diff --git a/apps/shell/Makefile.shell b/apps/shell/Makefile.shell index 61b79ff18..09c89dce7 100644 --- a/apps/shell/Makefile.shell +++ b/apps/shell/Makefile.shell @@ -10,7 +10,7 @@ shell_src = shell.c shell-reboot.c \ shell-rime-sendcmd.c shell-download.c shell-rime-neighbors.c \ shell-rime-unicast.c \ shell-tweet.c \ - shell-netperf.c + shell-netperf.c shell-memdebug.c shell_dsc = shell-dsc.c APPS += webbrowser diff --git a/apps/shell/shell-memdebug.c b/apps/shell/shell-memdebug.c new file mode 100644 index 000000000..e1dbeed9a --- /dev/null +++ b/apps/shell/shell-memdebug.c @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2008, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * $Id: shell-memdebug.c,v 1.1 2010/02/02 15:28:53 adamdunkels Exp $ + */ + +/** + * \file + * Shell commands for memory debugging + * \author + * Adam Dunkels + * Joakim Eriksson + */ + +#include "contiki.h" +#include "shell-memdebug.h" + +#include +#include + +/*---------------------------------------------------------------------------*/ +PROCESS(shell_poke_process, "poke"); +SHELL_COMMAND(poke_command, + "poke", + "poke
: write byte to address
", + &shell_poke_process); +PROCESS(shell_peek_process, "peek"); +SHELL_COMMAND(peek_command, + "peek", + "peek
: read a byte from address
", + &shell_peek_process); +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(shell_poke_process, ev, data) +{ + uint8_t *address; + uint8_t byte; + const char *args, *next; + + PROCESS_BEGIN(); + + args = data; + + if(args == NULL) { + shell_output_str(&poke_command, "usage 0", ""); + PROCESS_EXIT(); + } + + address = (uint8_t *)(int)shell_strtolong(args, &next); + if(next == args) { + shell_output_str(&poke_command, "usage 1", ""); + PROCESS_EXIT(); + } + + args = next; + byte = shell_strtolong(args, &next); + if(next == args) { + shell_output_str(&poke_command, "usage 2", ""); + PROCESS_EXIT(); + } + + printf("address %p byte 0x%02x\n", address, byte); + + *address = byte; + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(shell_peek_process, ev, data) +{ + uint8_t *address; + const char *args, *next; + char buf[32]; + + PROCESS_BEGIN(); + + args = data; + + if(args == NULL) { + shell_output_str(&peek_command, "usage 0", ""); + PROCESS_EXIT(); + } + + address = (uint8_t *)(int)shell_strtolong(args, &next); + if(next == args) { + shell_output_str(&peek_command, "usage 1", ""); + PROCESS_EXIT(); + } + + snprintf(buf, sizeof(buf), "0x%02x", *address); + + shell_output_str(&peek_command, buf, ""); + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ +void +shell_memdebug_init(void) +{ + shell_register_command(&poke_command); + shell_register_command(&peek_command); +} +/*---------------------------------------------------------------------------*/ diff --git a/apps/shell/shell-memdebug.h b/apps/shell/shell-memdebug.h new file mode 100644 index 000000000..0bae580f0 --- /dev/null +++ b/apps/shell/shell-memdebug.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2008, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * $Id: shell-memdebug.h,v 1.1 2010/02/02 15:28:53 adamdunkels Exp $ + */ + +/** + * \file + * Shell commands for memory debugging + * \author + * Adam Dunkels + */ + +#ifndef __SHELL_MEMDEBUG_H__ +#define __SHELL_MEMDEBUG_H__ + +#include "shell.h" + +void shell_memdebug_init(void); + +#endif /* __SHELL_MEMDEBUG_H__ */ diff --git a/apps/shell/shell.h b/apps/shell/shell.h index 37b3479d7..eba8f710f 100644 --- a/apps/shell/shell.h +++ b/apps/shell/shell.h @@ -48,7 +48,7 @@ * * This file is part of the Contiki operating system. * - * $Id: shell.h,v 1.20 2010/01/31 19:35:12 adamdunkels Exp $ + * $Id: shell.h,v 1.21 2010/02/02 15:28:53 adamdunkels Exp $ */ /** @@ -361,6 +361,7 @@ struct shell_input { #include "shell-file.h" #include "shell-httpd.h" #include "shell-irc.h" +#include "shell-memdebug.h" #include "shell-netfile.h" #include "shell-netperf.h" #include "shell-netstat.h"