Branch data Line data Source code
1 : : // $Id: DebugCmds.h 80 2004-07-14 20:15:50Z jason $
2 : : //
3 : : // Support routines to help deal with Bro debugging commands and
4 : : // implementation of most commands.
5 : :
6 : : #ifndef debug_cmds_h
7 : : #define debug_cmds_h
8 : :
9 : : #include <stdlib.h>
10 : : #include <string>
11 : : #include <vector>
12 : : using namespace std;
13 : :
14 : : #include "Queue.h"
15 : : #include "DebugCmdConstants.h"
16 : :
17 : : class DebugCmdInfo;
18 : 6 : declare(PQueue,DebugCmdInfo);
19 : :
20 : : class DebugCmdInfo {
21 : : public:
22 : : DebugCmdInfo(const DebugCmdInfo& info);
23 : :
24 : : DebugCmdInfo(DebugCmd cmd, const char* const* names, int num_names,
25 : : bool resume_execution, const char* const helpstring,
26 : : bool repeatable);
27 : :
28 : : DebugCmdInfo() : helpstring(0) {}
29 : :
30 : 0 : int Cmd() const { return cmd; }
31 : 0 : int NumNames() const { return num_names; }
32 : 0 : const vector<const char *>& Names() const { return names; }
33 : 0 : bool ResumeExecution() const { return resume_execution; }
34 : 0 : const char* Helpstring() const { return helpstring; }
35 : : bool Repeatable() const { return repeatable; }
36 : :
37 : : protected:
38 : : DebugCmd cmd;
39 : :
40 : : int num_names;
41 : : vector<const char*> names;
42 : :
43 : : // Whether executing this should restart execution of the script.
44 : : bool resume_execution;
45 : :
46 : : const char* const helpstring;
47 : :
48 : : // Does entering a blank line repeat this command?
49 : : bool repeatable;
50 : : };
51 : :
52 : : extern PQueue(DebugCmdInfo) g_DebugCmdInfos;
53 : :
54 : : void init_global_dbg_constants ();
55 : :
56 : : #define num_debug_cmds() (g_DebugCmdInfos.length())
57 : :
58 : : // Looks up the info record and returns it; if cmd is not found returns 0.
59 : : const DebugCmdInfo* get_debug_cmd_info(DebugCmd cmd);
60 : :
61 : : // The argument array_of_matches is an array of char*; each element
62 : : // is set equal to the command string that matches or nil depending
63 : : // on whether or not the prefix supplied matches a name (DebugCmdString)
64 : : // of the corresponding DebugCmd. The size of the array should be at
65 : : // least NUM_DEBUG_CMDS. The total number of matches is returned.
66 : : int find_all_matching_cmds(const string& prefix, const char* array_of_matches[]);
67 : :
68 : : // Implementation of debugging commands.
69 : : //
70 : : // These functions return <= 0 if failure, > 0 for success.
71 : : // More particular return values are command-specific: see comments w/function.
72 : :
73 : : typedef int DbgCmdFn(DebugCmd cmd, const vector<string>& args);
74 : :
75 : : DbgCmdFn dbg_cmd_backtrace;
76 : : DbgCmdFn dbg_cmd_frame;
77 : : DbgCmdFn dbg_cmd_help;
78 : : DbgCmdFn dbg_cmd_break;
79 : : DbgCmdFn dbg_cmd_break_condition;
80 : : DbgCmdFn dbg_cmd_break_set_state;
81 : : DbgCmdFn dbg_cmd_print;
82 : : DbgCmdFn dbg_cmd_info;
83 : : DbgCmdFn dbg_cmd_list;
84 : : DbgCmdFn dbg_cmd_trace;
85 : :
86 : : #endif
|