Add command-line option to set startup breakpoints

Author Mitja Felicijan <mitja.felicijan@gmail.com> 2026-01-17 02:21:19 +0100
Committer Mitja Felicijan <mitja.felicijan@gmail.com> 2026-01-17 02:21:19 +0100
Commit 184157ac185c981d9511e7a36ba21d35f29c0032 (patch)
-rw-r--r-- README.md 7
-rw-r--r-- tdbg.cpp 16
2 files changed, 21 insertions, 2 deletions
diff --git a/README.md b/README.md
...
33
./tdbg ./example -e MYENV=qwe -- arg1 arg2 arg3
33
./tdbg ./example -e MYENV=qwe -- arg1 arg2 arg3
34
```
34
```
35
  
35
  
  
36
Example with breakpoints:
  
37
  
  
38
```sh
  
39
./tdbg ./example -b main
  
40
./tdbg ./example -b example.c:54 -b example.c:60
  
41
```
  
42
  
36
### Interactive Commands
43
### Interactive Commands
37
  
44
  
38
| Key | Action                                                            |
45
| Key | Action                                                            |
...
diff --git a/tdbg.cpp b/tdbg.cpp
...
672
  
672
  
673
int main(int argc, char** argv) {
673
int main(int argc, char** argv) {
674
	std::vector<std::string> target_env;
674
	std::vector<std::string> target_env;
  
675
	std::vector<std::string> startup_breakpoints;
675
	std::vector<std::string> debuggee_args;
676
	std::vector<std::string> debuggee_args;
676
	std::string target_path;
677
	std::string target_path;
677
  
678
  
...
679
		std::string arg = argv[i];
680
		std::string arg = argv[i];
680
		if (arg == "-e" && i + 1 < argc) {
681
		if (arg == "-e" && i + 1 < argc) {
681
			target_env.push_back(argv[++i]);
682
			target_env.push_back(argv[++i]);
  
683
		} else if (arg == "-b" && i + 1 < argc) {
  
684
			startup_breakpoints.push_back(argv[++i]);
682
		} else if (arg == "--") {
685
		} else if (arg == "--") {
683
			for (int j = i + 1; j < argc; ++j) {
686
			for (int j = i + 1; j < argc; ++j) {
684
				debuggee_args.push_back(argv[j]);
687
				debuggee_args.push_back(argv[j]);
...
692
	}
695
	}
693
  
696
  
694
	if (target_path.empty()) {
697
	if (target_path.empty()) {
695
		std::cerr << "Usage: " << argv[0] << " [-e KEY=VALUE] ... <target_executable> [-- arg1 arg2 ...]\n";
698
		std::cerr << "Usage: " << argv[0] << " [-e KEY=VALUE] [-b BREAKPOINT] ... <target_executable> [-- arg1 arg2 ...]\n";
696
		return 1;
699
		return 1;
697
	}
700
	}
698
  
701
  
...
712
		return 1;
715
		return 1;
713
	}
716
	}
714
  
717
  
  
718
	std::vector<std::string> log_buffer;
  
719
	for (const auto& bp_spec : startup_breakpoints) {
  
720
		SBBreakpoint bp = create_breakpoint(target, bp_spec);
  
721
		if (bp.IsValid() && bp.GetNumLocations() > 0) {
  
722
			log_msg(log_buffer, "Set startup breakpoint: " + bp_spec);
  
723
		} else {
  
724
			log_msg(log_buffer, "Failed to set startup breakpoint: " + bp_spec);
  
725
		}
  
726
	}
  
727
  
715
	SBProcess process; 
728
	SBProcess process; 
716
	SBThread thread;
729
	SBThread thread;
717
  
730
  
...
721
	InputMode mode = INPUT_MODE_NORMAL;
734
	InputMode mode = INPUT_MODE_NORMAL;
722
	std::string input_buffer;
735
	std::string input_buffer;
723
	std::string current_source_filename;
736
	std::string current_source_filename;
724
	std::vector<std::string> log_buffer;
  
725
	std::vector<std::string> watch_expressions;
737
	std::vector<std::string> watch_expressions;
726
	int log_scroll_offset = 0;
738
	int log_scroll_offset = 0;
727
	int locals_scroll_offset = 0;
739
	int locals_scroll_offset = 0;
...