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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
|
//===-- CommandObjectProcess.cpp --------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "CommandObjectProcess.h"
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "lldb/Interpreter/Args.h"
#include "lldb/Interpreter/Options.h"
#include "lldb/Core/State.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "./CommandObjectThread.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
using namespace lldb;
using namespace lldb_private;
//-------------------------------------------------------------------------
// CommandObjectProcessLaunch
//-------------------------------------------------------------------------
class CommandObjectProcessLaunch : public CommandObject
{
public:
class CommandOptions : public Options
{
public:
CommandOptions () :
Options()
{
// Keep default values of all options in one place: ResetOptionValues ()
ResetOptionValues ();
}
~CommandOptions ()
{
}
Error
SetOptionValue (int option_idx, const char *option_arg)
{
Error error;
char short_option = (char) m_getopt_table[option_idx].val;
switch (short_option)
{
case 's': stop_at_entry = true; break;
case 'e': stderr_path = option_arg; break;
case 'i': stdin_path = option_arg; break;
case 'o': stdout_path = option_arg; break;
case 'p': plugin_name = option_arg; break;
default:
error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option);
break;
}
return error;
}
void
ResetOptionValues ()
{
Options::ResetOptionValues();
stop_at_entry = false;
stdin_path.clear();
stdout_path.clear();
stderr_path.clear();
plugin_name.clear();
}
const lldb::OptionDefinition*
GetDefinitions ()
{
return g_option_table;
}
// Options table: Required for subclasses of Options.
static lldb::OptionDefinition g_option_table[];
// Instance variables to hold the values for command options.
bool stop_at_entry;
std::string stderr_path;
std::string stdin_path;
std::string stdout_path;
std::string plugin_name;
};
CommandObjectProcessLaunch () :
CommandObject ("process launch",
"Launches the executable in the debugger.",
"process launch [<cmd-options>] [<arguments-for-running-the-program>]")
{
}
~CommandObjectProcessLaunch ()
{
}
Options *
GetOptions ()
{
return &m_options;
}
bool
Execute (Args& launch_args,
CommandContext *context,
CommandInterpreter *interpreter,
CommandReturnObject &result)
{
Target *target = context->GetTarget();
bool synchronous_execution = interpreter->GetSynchronous ();
// bool launched = false;
// bool stopped_after_launch = false;
if (target == NULL)
{
result.AppendError ("invalid target, set executable file using 'file' command");
result.SetStatus (eReturnStatusFailed);
return false;
}
// If our listener is NULL, users aren't allows to launch
Listener *listener = interpreter->GetListener();
if (listener == NULL)
{
result.AppendError ("operation not allowed through the command interpreter");
result.SetStatus (eReturnStatusFailed);
return false;
}
char filename[PATH_MAX];
Module *exe_module = target->GetExecutableModule().get();
exe_module->GetFileSpec().GetPath(filename, sizeof(filename));
Process *process = context->GetExecutionContext().process;
if (process)
{
if (process->IsAlive())
{
result.AppendErrorWithFormat ("Process %u is currently being debugged, kill the process before running again.\n",
process->GetID());
result.SetStatus (eReturnStatusFailed);
return false;
}
}
const char *plugin_name;
if (!m_options.plugin_name.empty())
plugin_name = m_options.plugin_name.c_str();
else
plugin_name = NULL;
process = target->CreateProcess (*listener, plugin_name).get();
const Args *environment = interpreter->GetEnvironmentVariables();
const Args *run_args = interpreter->GetProgramArguments();
// There are two possible sources of args to be passed to the process upon launching: Those the user
// typed at the run command (launch_args); or those the user pre-set in the run-args variable (run_args).
// If launch_args is empty, use run_args.
if (launch_args.GetArgumentCount() == 0)
{
if (run_args != NULL)
launch_args.AppendArguments (*run_args);
}
else
{
// launch-args was not empty; use that, AND re-set run-args to contains launch-args values.
StateVariable *run_args_var = interpreter->GetStateVariable ("run-args");
if (run_args_var != NULL)
{
run_args_var->ArrayClearValues();
run_args_var->GetArgs().AppendArguments (launch_args);
}
}
if (process)
{
const char *archname = exe_module->GetArchitecture().AsCString();
const char * stdin_path = NULL;
const char * stdout_path = NULL;
const char * stderr_path = NULL;
if (!(m_options.stdin_path.empty() &&
m_options.stdout_path.empty() &&
m_options.stderr_path.empty()))
{
stdin_path = m_options.stdin_path.empty() ? "/dev/null" : m_options.stdin_path.c_str();
stdout_path = m_options.stdout_path.empty() ? "/dev/null" : m_options.stdout_path.c_str();
stderr_path = m_options.stderr_path.empty() ? "/dev/null" : m_options.stderr_path.c_str();
}
Error error (process->Launch (launch_args.GetConstArgumentVector(),
environment ? environment->GetConstArgumentVector() : NULL,
stdin_path,
stdout_path,
stderr_path));
if (error.Success())
{
result.AppendMessageWithFormat ("Launching '%s' (%s)\n", filename, archname);
result.SetStatus (eReturnStatusSuccessContinuingNoResult);
if (m_options.stop_at_entry == false)
{
StateType state = process->WaitForProcessToStop (NULL);
if (state == eStateStopped)
{
// Call continue_command.
CommandReturnObject continue_result;
interpreter->HandleCommand("process continue", false, continue_result);
}
if (synchronous_execution)
{
result.SetDidChangeProcessState (true);
result.SetStatus (eReturnStatusSuccessFinishNoResult);
}
}
}
else
{
result.AppendErrorWithFormat ("Process launch failed: %s",
error.AsCString());
result.SetStatus (eReturnStatusFailed);
}
}
else
{
result.AppendErrorWithFormat ("Process launch failed: unable to create a process object.\n");
result.SetStatus (eReturnStatusFailed);
return false;
}
return result.Succeeded();
}
protected:
CommandOptions m_options;
};
lldb::OptionDefinition
CommandObjectProcessLaunch::CommandOptions::g_option_table[] =
{
{ LLDB_OPT_SET_1, false, "stop-at-entry", 's', no_argument, NULL, 0, NULL, "Stop at the entry point of the program when launching a process."},
{ LLDB_OPT_SET_1, false, "stdin", 'i', required_argument, NULL, 0, "<path>", "Redirect stdin for the process to <path>."},
{ LLDB_OPT_SET_1, false, "stdout", 'o', required_argument, NULL, 0, "<path>", "Redirect stdout for the process to <path>."},
{ LLDB_OPT_SET_1, false, "stderr", 'e', required_argument, NULL, 0, "<path>", "Redirect stderr for the process to <path>."},
{ LLDB_OPT_SET_1, false, "plugin", 'p', required_argument, NULL, 0, "<plugin>", "Name of the process plugin you want to use."},
{ 0, false, NULL, 0, 0, NULL, 0, NULL, NULL }
};
//-------------------------------------------------------------------------
// CommandObjectProcessAttach
//-------------------------------------------------------------------------
class CommandObjectProcessAttach : public CommandObject
{
public:
CommandObjectProcessAttach () :
CommandObject ("process attach",
"Attaches to a process.",
"process attach <cmd-options>")
{
SetHelpLong("Currently, you must set the executable file before you can attach "
"to a process.\n");
}
~CommandObjectProcessAttach ()
{
}
bool
Execute (Args& command,
CommandContext *context,
CommandInterpreter *interpreter,
CommandReturnObject &result)
{
Target *target = context->GetTarget();
if (target == NULL)
{
result.AppendError ("invalid target, set executable file using 'file' command");
result.SetStatus (eReturnStatusFailed);
return false;
}
// If our listener is NULL, users aren't allows to launch
Listener *listener = interpreter->GetListener();
if (listener == NULL)
{
result.AppendError ("operation not allowed through the command interpreter");
result.SetStatus (eReturnStatusFailed);
return false;
}
Process *process = context->GetExecutionContext().process;
if (process)
{
if (process->IsAlive())
{
result.AppendErrorWithFormat ("Process %u is currently being debugged, kill the process before attaching.\n", process->GetID());
result.SetStatus (eReturnStatusFailed);
return false;
}
}
if (command.GetArgumentCount())
{
result.AppendErrorWithFormat("Invalid arguments for '%s'.\nUsage: \n", m_cmd_name.c_str(), m_cmd_syntax.c_str());
result.SetStatus (eReturnStatusFailed);
}
else
{
const char *plugin_name = NULL;
if (!m_options.plugin_name.empty())
plugin_name = m_options.plugin_name.c_str();
process = target->CreateProcess (*listener, plugin_name).get();
if (process)
{
Error error;
int attach_pid = m_options.pid;
if (attach_pid != LLDB_INVALID_PROCESS_ID)
{
error = process->Attach (attach_pid);
if (error.Success())
{
result.SetStatus (eReturnStatusSuccessContinuingNoResult);
}
else
{
result.AppendErrorWithFormat ("Attaching to process %i failed: %s.\n",
attach_pid,
error.AsCString());
result.SetStatus (eReturnStatusFailed);
}
}
else if (!m_options.name.empty())
{
error = process->Attach (m_options.name.c_str(), m_options.waitfor);
if (error.Success())
{
result.SetStatus (eReturnStatusSuccessContinuingNoResult);
}
else
{
if (m_options.waitfor)
result.AppendErrorWithFormat ("Waiting for a process to launch named '%s': %s\n",
m_options.name.c_str(),
error.AsCString());
else
result.AppendErrorWithFormat ("Failed to a process named '%s': %s\n",
m_options.name.c_str(),
error.AsCString());
result.SetStatus (eReturnStatusFailed);
}
}
}
}
return result.Succeeded();
}
Options *
GetOptions ()
{
return &m_options;
}
class CommandOptions : public Options
{
public:
CommandOptions () :
Options()
{
// Keep default values of all options in one place: ResetOptionValues ()
ResetOptionValues ();
}
~CommandOptions ()
{
}
Error
SetOptionValue (int option_idx, const char *option_arg)
{
Error error;
char short_option = (char) m_getopt_table[option_idx].val;
bool success = false;
switch (short_option)
{
case 'p':
pid = Args::StringToUInt32 (option_arg, LLDB_INVALID_PROCESS_ID, 0, &success);
if (!success || pid == LLDB_INVALID_PROCESS_ID)
{
error.SetErrorStringWithFormat("Invalid process ID '%s'.\n", option_arg);
}
break;
case 'P':
plugin_name = option_arg;
break;
case 'n':
name.assign(option_arg);
break;
case 'w':
waitfor = true;
break;
default:
error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option);
break;
}
return error;
}
void
ResetOptionValues ()
{
Options::ResetOptionValues();
pid = LLDB_INVALID_PROCESS_ID;
name.clear();
waitfor = false;
}
const lldb::OptionDefinition*
GetDefinitions ()
{
return g_option_table;
}
// Options table: Required for subclasses of Options.
static lldb::OptionDefinition g_option_table[];
// Instance variables to hold the values for command options.
lldb::pid_t pid;
std::string plugin_name;
std::string name;
bool waitfor;
};
protected:
CommandOptions m_options;
};
lldb::OptionDefinition
CommandObjectProcessAttach::CommandOptions::g_option_table[] =
{
{ LLDB_OPT_SET_ALL, false, "plugin", 'P', required_argument, NULL, 0, "<plugin>", "Name of the process plugin you want to use."},
{ LLDB_OPT_SET_1, false, "pid", 'p', required_argument, NULL, 0, "<pid>", "The process ID of an existing process to attach to."},
{ LLDB_OPT_SET_2, true, "name", 'n', required_argument, NULL, 0, "<process-name>", "The name of the process to attach to."},
{ LLDB_OPT_SET_2, false, "waitfor", 'w', no_argument, NULL, 0, NULL, "Wait for the the process with <process-name> to launch."},
{ 0, false, NULL, 0, 0, NULL, 0, NULL, NULL }
};
//-------------------------------------------------------------------------
// CommandObjectProcessContinue
//-------------------------------------------------------------------------
class CommandObjectProcessContinue : public CommandObject
{
public:
CommandObjectProcessContinue () :
CommandObject ("process continue",
"Continues execution all threads in the current process.",
"process continue",
eFlagProcessMustBeLaunched | eFlagProcessMustBePaused)
{
}
~CommandObjectProcessContinue ()
{
}
bool
Execute (Args& command,
CommandContext *context,
CommandInterpreter *interpreter,
CommandReturnObject &result)
{
Process *process = context->GetExecutionContext().process;
bool synchronous_execution = interpreter->GetSynchronous ();
if (process == NULL)
{
result.AppendError ("no process to continue");
result.SetStatus (eReturnStatusFailed);
return false;
}
StateType state = process->GetState();
if (state == eStateStopped)
{
if (command.GetArgumentCount() != 0)
{
result.AppendErrorWithFormat ("The '%s' command does not take any arguments.\n", m_cmd_name.c_str());
result.SetStatus (eReturnStatusFailed);
return false;
}
const uint32_t num_threads = process->GetThreadList().GetSize();
// Set the actions that the threads should each take when resuming
for (uint32_t idx=0; idx<num_threads; ++idx)
{
process->GetThreadList().GetThreadAtIndex(idx)->SetResumeState (eStateRunning);
}
Error error(process->Resume());
if (error.Success())
{
result.AppendMessageWithFormat ("Resuming process %i\n", process->GetID());
if (synchronous_execution)
{
StateType state = process->WaitForProcessToStop (NULL);
result.SetDidChangeProcessState (true);
result.AppendMessageWithFormat ("Process %i %s\n", process->GetID(), StateAsCString (state));
result.SetStatus (eReturnStatusSuccessFinishNoResult);
}
else
{
result.SetStatus (eReturnStatusSuccessContinuingNoResult);
}
}
else
{
result.AppendErrorWithFormat("Failed to resume process: %s.\n", error.AsCString());
result.SetStatus (eReturnStatusFailed);
}
}
else
{
result.AppendErrorWithFormat ("Process cannot be continued from its current state (%s).\n",
StateAsCString(state));
result.SetStatus (eReturnStatusFailed);
}
return result.Succeeded();
}
};
//-------------------------------------------------------------------------
// CommandObjectProcessDetach
//-------------------------------------------------------------------------
class CommandObjectProcessDetach : public CommandObject
{
public:
CommandObjectProcessDetach () :
CommandObject ("process detach",
"Detaches from the current process being debugged.",
"process detach",
eFlagProcessMustBeLaunched)
{
}
~CommandObjectProcessDetach ()
{
}
bool
Execute (Args& command,
CommandContext *context,
CommandInterpreter *interpreter,
CommandReturnObject &result)
{
Process *process = context->GetExecutionContext().process;
if (process == NULL)
{
result.AppendError ("must have a valid process in order to detach");
result.SetStatus (eReturnStatusFailed);
return false;
}
Error error (process->Detach());
if (error.Success())
{
result.SetStatus (eReturnStatusSuccessFinishResult);
}
else
{
result.AppendErrorWithFormat ("Detach failed: %s\n", error.AsCString());
result.SetStatus (eReturnStatusFailed);
return false;
}
return result.Succeeded();
}
};
//-------------------------------------------------------------------------
// CommandObjectProcessSignal
//-------------------------------------------------------------------------
class CommandObjectProcessSignal : public CommandObject
{
public:
CommandObjectProcessSignal () :
CommandObject ("process signal",
"Sends a UNIX signal to the current process being debugged.",
"process signal <unix-signal-number>")
{
}
~CommandObjectProcessSignal ()
{
}
bool
Execute (Args& command,
CommandContext *context,
CommandInterpreter *interpreter,
CommandReturnObject &result)
{
Process *process = context->GetExecutionContext().process;
if (process == NULL)
{
result.AppendError ("no process to signal");
result.SetStatus (eReturnStatusFailed);
return false;
}
if (command.GetArgumentCount() == 1)
{
int signo = Args::StringToSInt32(command.GetArgumentAtIndex(0), -1, 0);
if (signo == -1)
{
result.AppendErrorWithFormat ("Invalid signal argument '%s'.\n", command.GetArgumentAtIndex(0));
result.SetStatus (eReturnStatusFailed);
}
else
{
Error error (process->Signal (signo));
if (error.Success())
{
result.SetStatus (eReturnStatusSuccessFinishResult);
}
else
{
result.AppendErrorWithFormat ("Failed to send signal %i: %s\n", signo, error.AsCString());
result.SetStatus (eReturnStatusFailed);
}
}
}
else
{
result.AppendErrorWithFormat("'%s' takes exactly one signal number argument:\nUsage: \n", m_cmd_name.c_str(),
m_cmd_syntax.c_str());
result.SetStatus (eReturnStatusFailed);
}
return result.Succeeded();
}
};
//-------------------------------------------------------------------------
// CommandObjectProcessInterrupt
//-------------------------------------------------------------------------
class CommandObjectProcessInterrupt : public CommandObject
{
public:
CommandObjectProcessInterrupt () :
CommandObject ("process interrupt",
"Interrupts the current process being debugged.",
"process interrupt",
eFlagProcessMustBeLaunched)
{
}
~CommandObjectProcessInterrupt ()
{
}
bool
Execute (Args& command,
CommandContext *context,
CommandInterpreter *interpreter,
CommandReturnObject &result)
{
Process *process = context->GetExecutionContext().process;
if (process == NULL)
{
result.AppendError ("no process to halt");
result.SetStatus (eReturnStatusFailed);
return false;
}
if (command.GetArgumentCount() == 0)
{
Error error(process->Halt ());
if (error.Success())
{
result.SetStatus (eReturnStatusSuccessFinishResult);
// Maybe we should add a "SuspendThreadPlans so we
// can halt, and keep in place all the current thread plans.
process->GetThreadList().DiscardThreadPlans();
}
else
{
result.AppendErrorWithFormat ("Failed to halt process: %s\n", error.AsCString());
result.SetStatus (eReturnStatusFailed);
}
}
else
{
result.AppendErrorWithFormat("'%s' takes no arguments:\nUsage: \n",
m_cmd_name.c_str(),
m_cmd_syntax.c_str());
result.SetStatus (eReturnStatusFailed);
}
return result.Succeeded();
}
};
//-------------------------------------------------------------------------
// CommandObjectProcessKill
//-------------------------------------------------------------------------
class CommandObjectProcessKill : public CommandObject
{
public:
CommandObjectProcessKill () :
CommandObject ("process kill",
"Terminates the current process being debugged.",
"process kill",
eFlagProcessMustBeLaunched)
{
}
~CommandObjectProcessKill ()
{
}
bool
Execute (Args& command,
CommandContext *context,
CommandInterpreter *interpreter,
CommandReturnObject &result)
{
Process *process = context->GetExecutionContext().process;
if (process == NULL)
{
result.AppendError ("no process to kill");
result.SetStatus (eReturnStatusFailed);
return false;
}
if (command.GetArgumentCount() == 0)
{
Error error (process->Destroy());
if (error.Success())
{
result.SetStatus (eReturnStatusSuccessFinishResult);
}
else
{
result.AppendErrorWithFormat ("Failed to kill process: %s\n", error.AsCString());
result.SetStatus (eReturnStatusFailed);
}
}
else
{
result.AppendErrorWithFormat("'%s' takes no arguments:\nUsage: \n",
m_cmd_name.c_str(),
m_cmd_syntax.c_str());
result.SetStatus (eReturnStatusFailed);
}
return result.Succeeded();
}
};
//-------------------------------------------------------------------------
// CommandObjectProcessStatus
//-------------------------------------------------------------------------
class CommandObjectProcessStatus : public CommandObject
{
public:
CommandObjectProcessStatus () :
CommandObject ("status",
"Shows the current status and location of executing process.",
"status",
0)
{
}
~CommandObjectProcessStatus()
{
}
bool
Execute
(
Args& command,
CommandContext *context,
CommandInterpreter *interpreter,
CommandReturnObject &result
)
{
StreamString &output_stream = result.GetOutputStream();
result.SetStatus (eReturnStatusSuccessFinishNoResult);
ExecutionContext exe_ctx(context->GetExecutionContext());
if (exe_ctx.process)
{
const StateType state = exe_ctx.process->GetState();
if (StateIsStoppedState(state))
{
if (state == eStateExited)
{
int exit_status = exe_ctx.process->GetExitStatus();
const char *exit_description = exe_ctx.process->GetExitDescription();
output_stream.Printf ("Process %d exited with status = %i (0x%8.8x) %s\n",
exe_ctx.process->GetID(),
exit_status,
exit_status,
exit_description ? exit_description : "");
}
else
{
output_stream.Printf ("Process %d %s\n", exe_ctx.process->GetID(), StateAsCString (state));
if (exe_ctx.thread == NULL)
exe_ctx.thread = exe_ctx.process->GetThreadList().GetThreadAtIndex(0).get();
if (exe_ctx.thread != NULL)
{
DisplayThreadsInfo (interpreter, &exe_ctx, result, true, true);
}
else
{
result.AppendError ("No valid thread found in current process.");
result.SetStatus (eReturnStatusFailed);
}
}
}
else
{
output_stream.Printf ("Process %d is running.\n",
exe_ctx.process->GetID());
}
}
else
{
result.AppendError ("No current location or status available.");
result.SetStatus (eReturnStatusFailed);
}
return result.Succeeded();
}
};
//-------------------------------------------------------------------------
// CommandObjectMultiwordProcess
//-------------------------------------------------------------------------
CommandObjectMultiwordProcess::CommandObjectMultiwordProcess (CommandInterpreter *interpreter) :
CommandObjectMultiword ("process",
"A set of commands for operating on a process.",
"process <subcommand> [<subcommand-options>]")
{
LoadSubCommand (CommandObjectSP (new CommandObjectProcessAttach ()), "attach", interpreter);
LoadSubCommand (CommandObjectSP (new CommandObjectProcessLaunch ()), "launch", interpreter);
LoadSubCommand (CommandObjectSP (new CommandObjectProcessContinue ()), "continue", interpreter);
LoadSubCommand (CommandObjectSP (new CommandObjectProcessDetach ()), "detach", interpreter);
LoadSubCommand (CommandObjectSP (new CommandObjectProcessSignal ()), "signal", interpreter);
LoadSubCommand (CommandObjectSP (new CommandObjectProcessStatus ()), "status", interpreter);
LoadSubCommand (CommandObjectSP (new CommandObjectProcessInterrupt ()), "interrupt", interpreter);
LoadSubCommand (CommandObjectSP (new CommandObjectProcessKill ()), "kill", interpreter);
}
CommandObjectMultiwordProcess::~CommandObjectMultiwordProcess ()
{
}
|