-
-
Notifications
You must be signed in to change notification settings - Fork 781
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
memwatch - read memory while running
- Loading branch information
Showing
5 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,7 @@ SRC = \ | |
kinetis.c \ | ||
main.c \ | ||
maths_utils.c \ | ||
memwatch.c \ | ||
morse.c \ | ||
msp432e4.c \ | ||
msp432p4.c \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef MEMWATCH_H | ||
#define MEMWATCH_H | ||
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
#include <target.h> | ||
|
||
#define MEMWATCH_NUM 8 | ||
/* string length has to be long enough to store an address 0x20000000 */ | ||
#define MEMWATCH_STRLEN 12 | ||
|
||
typedef enum memwatch_format { | ||
MEMWATCH_FMT_SIGNED, | ||
MEMWATCH_FMT_UNSIGNED, | ||
MEMWATCH_FMT_HEX | ||
} memwatch_format_e; | ||
|
||
typedef struct { | ||
uint32_t addr; | ||
uint32_t value; | ||
char name[MEMWATCH_STRLEN]; | ||
memwatch_format_e format; | ||
} memwatch_s; | ||
|
||
extern memwatch_s memwatch_table[MEMWATCH_NUM]; | ||
extern uint32_t memwatch_cnt; | ||
extern void poll_memwatch(target_s *cur_target); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "general.h" | ||
#include "gdb_packet.h" | ||
#include "memwatch.h" | ||
#if PC_HOSTED == 1 | ||
#include <unistd.h> | ||
#else | ||
#include "usb_serial.h" | ||
#endif | ||
|
||
memwatch_s memwatch_table[MEMWATCH_NUM]; | ||
uint32_t memwatch_cnt = 0; | ||
|
||
void poll_memwatch(target_s *cur_target) | ||
{ | ||
uint32_t val; | ||
char buf[64]; | ||
uint32_t len; | ||
if (!cur_target || (memwatch_cnt == 0)) | ||
return; | ||
|
||
for (uint32_t i = 0; i < memwatch_cnt; i++) { | ||
if (!target_mem_read(cur_target, &val, memwatch_table[i].addr, sizeof(val)) && | ||
(val != memwatch_table[i].value)) { | ||
switch (memwatch_table[i].format) { | ||
case MEMWATCH_FMT_SIGNED: | ||
len = snprintf(buf, sizeof(buf), "%s: %" PRId32 "\r\n", memwatch_table[i].name, val); | ||
break; | ||
case MEMWATCH_FMT_UNSIGNED: | ||
len = snprintf(buf, sizeof(buf), "%s: %" PRIu32 "\r\n", memwatch_table[i].name, val); | ||
break; | ||
case MEMWATCH_FMT_HEX: | ||
default: | ||
len = snprintf(buf, sizeof(buf), "%s: 0x%" PRIx32 "\r\n", memwatch_table[i].name, val); | ||
break; | ||
} | ||
#if PC_HOSTED == 1 | ||
int l = write(1, buf, len); | ||
(void)l; | ||
#else | ||
debug_serial_fifo_send(buf, 0, len); | ||
#endif | ||
memwatch_table[i].value = val; | ||
} | ||
} | ||
return; | ||
} |