-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti_session.py
More file actions
132 lines (106 loc) · 3.81 KB
/
multi_session.py
File metadata and controls
132 lines (106 loc) · 3.81 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
"""
Example demonstrating multi-session debugging
"""
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from src.debugger import AIDebugger
import json
def main():
"""
Example: Managing multiple debugging sessions
This example shows how to:
1. Create multiple debugging sessions
2. List all active sessions
3. Switch between sessions
4. Close specific sessions
"""
debugger = AIDebugger()
print("=" * 60)
print("Multi-Session Debugging Example")
print("=" * 60)
# Programs to debug (replace with your programs)
programs = [
"./program1",
"./program2",
"./program3"
]
session_ids = []
try:
# Create multiple sessions
print("\n[1] Creating multiple sessions...")
for i, program in enumerate(programs):
result = debugger.execute_command(json.dumps({
'action': 'create_session',
'params': {
'program_path': program
}
}))
response = json.loads(result)
if response['success']:
session_id = response['result']['session_id']
session_ids.append(session_id)
print(f" ✓ Session {i+1}: {session_id[:8]}... ({program})")
else:
print(f" ✗ Failed to create session for {program}")
# List all sessions
print("\n[2] Listing all sessions...")
result = debugger.execute_command(json.dumps({
'action': 'list_sessions'
}))
response = json.loads(result)
if response['success']:
sessions = response['result']
print(f" Active sessions: {len(sessions)}")
for session in sessions:
print(f" - {session['id'][:8]}... | {session['program']} | {session['state']}")
# Work with first session
if session_ids:
print("\n[3] Working with first session...")
session_id = session_ids[0]
# Set breakpoint
result = debugger.execute_command(json.dumps({
'action': 'set_breakpoint',
'params': {
'session_id': session_id,
'location': 'main'
}
}))
print(f" ✓ Set breakpoint in session {session_id[:8]}...")
# Run program
result = debugger.execute_command(json.dumps({
'action': 'run',
'params': {
'session_id': session_id
}
}))
print(f" ✓ Running program in session {session_id[:8]}...")
# Close sessions one by one
print("\n[4] Closing sessions...")
for i, session_id in enumerate(session_ids):
result = debugger.execute_command(json.dumps({
'action': 'close_session',
'params': {
'session_id': session_id
}
}))
response = json.loads(result)
if response['success']:
print(f" ✓ Closed session {i+1}: {session_id[:8]}...")
# Verify all sessions closed
result = debugger.execute_command(json.dumps({
'action': 'list_sessions'
}))
response = json.loads(result)
print(f"\n[5] Remaining sessions: {len(response['result'])}")
except Exception as e:
print(f"\n✗ Error: {e}")
import traceback
traceback.print_exc()
finally:
debugger.cleanup()
print("\n" + "=" * 60)
print("Example completed")
print("=" * 60)
if __name__ == "__main__":
main()