提交 8da72079 编写于 作者: Z Zihao Yu

monitor,diff-test: add port to QEMU

* now different instances can connect to QEMU via different ports
上级 9738abcc
......@@ -45,7 +45,7 @@ void difftest_skip_dut(int nr_ref, int nr_dut) {
bool isa_difftest_checkregs(CPU_state *ref_r, vaddr_t pc);
void isa_difftest_attach(void);
void init_difftest(char *ref_so_file, long img_size) {
void init_difftest(char *ref_so_file, long img_size, int port) {
#ifndef DIFF_TEST
return;
#endif
......@@ -68,7 +68,7 @@ void init_difftest(char *ref_so_file, long img_size) {
ref_difftest_exec = dlsym(handle, "difftest_exec");
assert(ref_difftest_exec);
void (*ref_difftest_init)(void) = dlsym(handle, "difftest_init");
void (*ref_difftest_init)(int) = dlsym(handle, "difftest_init");
assert(ref_difftest_init);
Log("Differential testing: \33[1;32m%s\33[0m", "ON");
......@@ -76,7 +76,7 @@ void init_difftest(char *ref_so_file, long img_size) {
"This will help you a lot for debugging, but also significantly reduce the performance. "
"If it is not necessary, you can turn it off in include/common.h.", ref_so_file);
ref_difftest_init();
ref_difftest_init(port);
ref_difftest_memcpy_from_dut(PC_START, guest_to_host(IMAGE_START), img_size);
char *mainargs = guest_to_host(0);
ref_difftest_memcpy_from_dut(PC_START - IMAGE_START, mainargs, strlen(mainargs) + 1);
......
......@@ -7,13 +7,14 @@ void init_isa();
void init_regex();
void init_wp_pool();
void init_device();
void init_difftest(char *ref_so_file, long img_size);
void init_difftest(char *ref_so_file, long img_size, int port);
static char *mainargs = "";
static char *log_file = NULL;
static char *diff_so_file = NULL;
static char *img_file = NULL;
static int is_batch_mode = false;
static int difftest_port = 1234;
static inline void welcome() {
#ifdef DEBUG
......@@ -64,10 +65,11 @@ static inline long load_img() {
static inline void parse_args(int argc, char *argv[]) {
int o;
while ( (o = getopt(argc, argv, "-bl:d:a:")) != -1) {
while ( (o = getopt(argc, argv, "-bl:d:a:p:")) != -1) {
switch (o) {
case 'b': is_batch_mode = true; break;
case 'a': mainargs = optarg; break;
case 'p': sscanf(optarg, "%d", &difftest_port); break;
case 'l': log_file = optarg; break;
case 'd': diff_so_file = optarg; break;
case 1:
......@@ -105,7 +107,7 @@ int init_monitor(int argc, char *argv[]) {
init_device();
/* Initialize differential testing. */
init_difftest(diff_so_file, img_size);
init_difftest(diff_so_file, img_size, difftest_port);
/* Display welcome message. */
welcome();
......
......@@ -3,7 +3,7 @@
#include <signal.h>
#include "isa.h"
bool gdb_connect_qemu(void);
bool gdb_connect_qemu(int);
bool gdb_memcpy_to_qemu(uint32_t, void *, int);
bool gdb_getregs(union isa_gdb_regs *);
bool gdb_setregs(union isa_gdb_regs *);
......@@ -34,7 +34,10 @@ void difftest_exec(uint64_t n) {
while (n --) gdb_si();
}
void difftest_init(void) {
void difftest_init(int port) {
char buf[32];
sprintf(buf, "tcp::%d", port);
int ppid_before_fork = getpid();
int pid = fork();
if (pid == -1) {
......@@ -57,15 +60,15 @@ void difftest_init(void) {
}
close(STDIN_FILENO);
execlp(ISA_QEMU_BIN, ISA_QEMU_BIN, ISA_QEMU_ARGS "-S", "-s", "-nographic", NULL);
execlp(ISA_QEMU_BIN, ISA_QEMU_BIN, ISA_QEMU_ARGS "-S", "-gdb", buf, "-nographic", NULL);
perror("exec");
assert(0);
}
else {
// father
gdb_connect_qemu();
printf("Connect to QEMU successfully\n");
gdb_connect_qemu(port);
printf("Connect to QEMU with %s tcpsuccessfully\n", buf);
atexit(gdb_exit);
......
......@@ -2,9 +2,9 @@
static struct gdb_conn *conn;
bool gdb_connect_qemu(void) {
bool gdb_connect_qemu(int port) {
// connect to gdbserver on localhost port 1234
while ((conn = gdb_begin_inet("127.0.0.1", 1234)) == NULL) {
while ((conn = gdb_begin_inet("127.0.0.1", port)) == NULL) {
usleep(1);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册