1
+ use std:: io;
2
+
3
+ use clap:: { Error , Parser , Subcommand } ;
4
+
5
+
6
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord ) ]
7
+ pub enum InteractiveState {
8
+ DISABLED ,
9
+ ENABLED ,
10
+ WAITING_FOR_BREAKPOINT ,
11
+ }
12
+
13
+ impl InteractiveState {
14
+ pub fn is_enabled ( & self ) -> bool { return * self == Self :: ENABLED }
15
+ pub fn is_disabled ( & self ) -> bool { return * self == Self :: DISABLED }
16
+ pub fn is_waiting_bp ( & self ) -> bool { return * self == Self :: WAITING_FOR_BREAKPOINT }
17
+ }
18
+
19
+ #[ derive( Parser , Debug ) ]
20
+ #[ command( name = ">" , about = "An interactive debuging tool" , long_about = None ) ]
21
+ pub struct InteractiveCli {
22
+ #[ command( subcommand) ]
23
+ pub cmd : Command ,
24
+ }
25
+
26
+ #[ derive( Subcommand , Debug ) ]
27
+ pub enum Command {
28
+ /// Proceed to the next instruction (alias: n)
29
+ #[ command( alias = "n" ) ]
30
+ NEXT ,
31
+
32
+ /// Continue until the next breakpoint (alias: nb)
33
+ #[ command( alias = "nb" ) ]
34
+ NEXT_BREAKPOINT ,
35
+
36
+ /// Add a breakpoint at a specified line (alias: ab)
37
+ #[ command( alias = "ab" ) ]
38
+ ADD_BREAKPOINT {
39
+ /// Line number for the breakpoint
40
+ line : usize ,
41
+ } ,
42
+
43
+ /// Delete a breakpoint at a specified line if exists (alias: db)
44
+ #[ command( alias = "db" ) ]
45
+ DELETE_BREAKPOINT {
46
+ /// Line number of the breakpoint to delete
47
+ line : usize ,
48
+ } ,
49
+
50
+ /// List all breakpoints (alias: lb)
51
+ #[ command( alias = "lb" ) ]
52
+ LIST_BREAKPOINTS ,
53
+
54
+ /// Aborts execution (alias: q)
55
+ #[ command( alias = "q" ) ]
56
+ QUIT ,
57
+
58
+ /// Disables interactive mode and finishes execution (alias: f)
59
+ #[ command( alias = "f" ) ]
60
+ FINISH ,
61
+
62
+ /// Print memory from a start address to an end address (alias: m)
63
+ #[ command( alias = "m" ) ]
64
+ MEM {
65
+ /// Inclusive start address of memory
66
+ #[ arg( short = 'f' , long = "from" , short, default_value_t = 0 ) ]
67
+ from : usize ,
68
+ /// Exclusive end address of memory
69
+ #[ arg( short, long, default_value_t = 512 ) ]
70
+ to : usize ,
71
+ /// File where u want to store a snapshot
72
+ #[ arg( long = "file" ) ]
73
+ file : Option < String >
74
+ } ,
75
+ }
76
+
77
+ impl InteractiveCli {
78
+
79
+ pub fn read ( ) -> Result < InteractiveCli , Error > {
80
+ let mut input = String :: new ( ) ;
81
+ io:: stdin ( ) . read_line ( & mut input) . expect ( "Failed to read line" ) ;
82
+ let mut args: Vec < & str > = input. trim ( ) . split_whitespace ( ) . collect ( ) ;
83
+ args. insert ( 0 , "" ) ;
84
+ InteractiveCli :: try_parse_from ( args)
85
+ }
86
+
87
+ pub fn print_start_baner ( ) {
88
+ println ! ( "_________ ________ _ ____ ___" ) ;
89
+ println ! ( "| ___ \\ \\ / / __ \\ | | | | \\ / |" ) ;
90
+ println ! ( "| |_/ / . . | / \\ / | | | | . . |" ) ;
91
+ println ! ( "| __/| |\\ /| | | | | | | |\\ /| |" ) ;
92
+ println ! ( "| | | | | | \\ __/\\ \\ \\ _/ / | | |" ) ;
93
+ println ! ( "\\ _| \\ _| |_\\ /____/ \\ ___/|_| |_| by poneciak" ) ;
94
+ println ! ( "Welcome to interactive mode type 'help' for more info" ) ;
95
+ println ! ( "Every instruction is displayed and then you can type your command" ) ;
96
+ println ! ( "" ) ;
97
+ }
98
+ }
0 commit comments