> compile NEMU

ysyx_22040000 李心杨
Linux calcite 6.1.75 #1-NixOS SMP PREEMPT_DYNAMIC Thu Jan 25 23:27:52 UTC 2024 x86_64 GNU/Linux
 18:43:12  up 1 day  4:19,  2 users,  load average: 1.84, 1.38, 0.75
This commit is contained in:
tracer-ysyx 2024-02-08 18:43:12 +08:00 committed by xinyangli
parent ace6b4a72b
commit 515e7be314
3 changed files with 68 additions and 52 deletions

View file

@ -32,6 +32,7 @@ static int is_batch_mode = false;
static int cmd_help(char *args); static int cmd_help(char *args);
static int cmd_c(char *args); static int cmd_c(char *args);
static int cmd_q(char *args); static int cmd_q(char *args);
static int cmd_w(char *args);
static int cmd_x(char *args); static int cmd_x(char *args);
static int cmd_si(char *args); static int cmd_si(char *args);
static int cmd_info(char *args); static int cmd_info(char *args);
@ -55,6 +56,7 @@ static struct CommandTable {
{"c", "Continue the execution of the program", cmd_c, NULL, 0}, {"c", "Continue the execution of the program", cmd_c, NULL, 0},
{"q", "Exit NEMU", cmd_q, NULL, 0}, {"q", "Exit NEMU", cmd_q, NULL, 0},
{"x", "Examine content of physical memory address", cmd_x, NULL, 0}, {"x", "Examine content of physical memory address", cmd_x, NULL, 0},
{"w", "Break when expression is changed", cmd_w, NULL, 0},
{"si", "Execute next [n] program line", cmd_si, NULL, 0}, {"si", "Execute next [n] program line", cmd_si, NULL, 0},
{"info", "Print information of registers or watchpoints", cmd_info, {"info", "Print information of registers or watchpoints", cmd_info,
cmd_info_table, ARRLEN(cmd_info_table)}, cmd_info_table, ARRLEN(cmd_info_table)},
@ -181,6 +183,18 @@ static int cmd_info_w(char *args) {
return 0; return 0;
} }
static int cmd_w(char *args) {
char *expr = strtok(NULL, " ");
bool success = false;
parse_expr(expr, &success);
if (!success) {
Error("Failed to parse given expression %s", expr);
return 0;
}
wp_add(expr);
return 0;
}
static int cmd_x(char *args) { static int cmd_x(char *args) {
char *arg = strtok(NULL, " "); char *arg = strtok(NULL, " ");
bool res = false; bool res = false;

View file

@ -19,5 +19,7 @@
#include <common.h> #include <common.h>
word_t parse_expr(const char *arg, bool *success); word_t parse_expr(const char *arg, bool *success);
int wp_add(char * expr);
int wp_remove_by_number(int number);
#endif #endif

View file

@ -27,8 +27,8 @@ typedef struct watchpoint {
} WP; } WP;
static WP wp_pool[NR_WP] = {}; static WP wp_pool[NR_WP] = {};
static WP *head = NULL, *free_ = NULL; static WP *head = NULL, *tail = NULL, *free_ = NULL;
// static int wp_count = 0; static int wp_count = 0;
void init_wp_pool() { void init_wp_pool() {
int i; int i;
@ -41,62 +41,62 @@ void init_wp_pool() {
free_ = wp_pool; free_ = wp_pool;
} }
// static WP *wp_new() { static WP *wp_new() {
// if (free_ == NULL) { if (free_ == NULL) {
// Error("wp_pool: Watchpoint pool not initialized or is full."); Error("wp_pool: Watchpoint pool not initialized or is full.");
// return NULL; return NULL;
// } }
// WP *ret = free_; WP *ret = free_;
// free_ = free_->next; free_ = free_->next;
// ret->NO = 0; ret->NO = 0;
// ret->next = NULL; ret->next = NULL;
// return ret; return ret;
// } }
// static void wp_delete(WP *wp) { static void wp_delete(WP *wp) {
// assert(wp); assert(wp);
// wp->next = free_; wp->next = free_;
// free_ = wp; free_ = wp;
// } }
// static int wp_add(char * expr) { int wp_add(char * expr) {
// WP *wp = wp_new(); WP *wp = wp_new();
// if (wp == NULL) { if (wp == NULL) {
// Error("watchpoint: Failed to add watchpoint, pool is full."); Error("watchpoint: Failed to add watchpoint, pool is full.");
// return 1; return 1;
// } }
// wp->NO = wp_count++; wp->NO = wp_count++;
// if (tail == NULL) { if (tail == NULL) {
// head = wp; head = wp;
// tail = wp; tail = wp;
// } else { } else {
// tail->next = wp; tail->next = wp;
// tail = wp; tail = wp;
// } }
// return 0; return 0;
// } }
// static int wp_remove_by_number(int number) { int wp_remove_by_number(int number) {
// WP *target_prev; WP *target_prev;
// // Find previous node of target number // Find previous node of target number
// for (target_prev = head; target_prev != NULL && target_prev->next->NO != number; target_prev = target_prev->next) ; for (target_prev = head; target_prev != NULL && target_prev->next->NO != number; target_prev = target_prev->next) ;
// if (target_prev == NULL) { if (target_prev == NULL) {
// Error("Watchpoint not found, you can check current watchpoints with `info w`"); Error("Watchpoint not found, you can check current watchpoints with `info w`");
// return 1; return 1;
// } }
// WP *target = target_prev->next; WP *target = target_prev->next;
// target_prev->next = target->next; target_prev->next = target->next;
// if (target == head) { if (target == head) {
// head = target->next; head = target->next;
// } else if (target == tail) { } else if (target == tail) {
// tail = target_prev; tail = target_prev;
// } }
// wp_delete(target); wp_delete(target);
// return 0; return 0;
// } }
static bool wp_check_change(WP* wp) { static bool wp_check_change(WP* wp) {
bool success = false; bool success = false;