/
ydb.h
64 lines (50 loc) · 1.36 KB
/
ydb.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef _DEBUGGER_YDB_H_
#define _DEBUGGER_YDB_H_
#include <vector>
#include <string>
#include <map>
#include <stdio.h>
#include <sys/ptrace.h>
#include <sys/reg.h>
#define ERROR( _fmt_, args... ) \
do{\
fprintf( stderr, "[%s][%s][%d] " _fmt_"\n", __FILE__, __FUNCTION__, __LINE__, ##args );\
}while(0)
#define LOG( _fmt_, args... ) \
do{\
fprintf( stdout, _fmt_"\n", ##args );\
}while(0)
class Debugger{
public:
Debugger(const char *program_file);
// int init(const char *program_file);
int run();
private:
char *skip_space(char *p_str) {
while (*p_str == ' ') {
p_str++;
}
return *p_str == '\0' ? NULL : p_str;
}
int parse_line(char *line_text);
int handle_command();
// command handler
int continue_run();
int exec_next_instr();
int set_breakpoint(void *addr);
int print_regs();
int print_var(void *addr);
// util
bool has_breakpoint();
int disable_breakpoint();
long get_eip();
static const int MAX_LINE = 1024;
enum {RUN, CONTINUE, NEXTINSTR, BREAKPOINT, INFO, PRINT, QUIT};
std::map<std::string, int> dict;
std::vector<std::string> command;
std::map<int, unsigned> breakpoints; // key:addr, value:orig data
bool is_in_breakpoint;
pid_t child_pid;
const char *program_file;
};
#endif // _DEBUGGER_YDB_H_