Skip to content

Commit 9a9b587

Browse files
committed
Enhance argument parsing by setting a default BTF vmlinux path in the help message and during initialization and compilation.
1 parent e2db5cc commit 9a9b587

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/main.ml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ let rec parse_args () =
3838
printf " Examples: kprobe/sys_read, kprobe/vfs_write, kprobe/tcp_sendmsg\n";
3939
printf " struct_ops: tcp_congestion_ops | bpf_iter_ops | bpf_struct_ops_test | custom_name\n";
4040
printf " project_name: Name of the project directory to create\n";
41-
printf " --btf-vmlinux-path: Path to BTF vmlinux file for type/struct_ops extraction\n\n";
41+
printf " --btf-vmlinux-path: Path to BTF vmlinux file (default: /sys/kernel/btf/vmlinux)\n\n";
4242
printf " compile <input_file> [options]\n";
4343
printf " Compile KernelScript source to C code\n";
4444
printf " -o, --output <dir> Specify output directory\n";
4545
printf " -v, --verbose Enable verbose output\n";
4646
printf " --no-makefile Don't generate Makefile\n";
4747
printf " --test Compile in test mode (only @test functions become main)\n";
4848
printf " --builtin-path <path> Specify path to builtin KernelScript files\n";
49-
printf " --btf-vmlinux-path <path> Specify path to BTF vmlinux file\n";
49+
printf " --btf-vmlinux-path <path> Path to BTF vmlinux file (default: /sys/kernel/btf/vmlinux)\n";
5050
exit 0
5151
| _ :: "init" :: rest -> parse_init_args rest
5252
| _ :: "compile" :: rest -> parse_compile_args rest
@@ -64,7 +64,12 @@ and parse_init_args args =
6464
| [] ->
6565
(match (prog_type_opt, project_name_opt) with
6666
| (Some prog_type, Some project_name) ->
67-
Init { prog_type; project_name; btf_path = btf_path_opt }
67+
(* Set default BTF path if none provided *)
68+
let final_btf_path = match btf_path_opt with
69+
| Some path -> Some path
70+
| None -> Some "/sys/kernel/btf/vmlinux"
71+
in
72+
Init { prog_type; project_name; btf_path = final_btf_path }
6873
| (None, _) ->
6974
printf "Error: Missing program type for init command\n";
7075
exit 1
@@ -93,7 +98,12 @@ and parse_compile_args args =
9398
| [] ->
9499
(match input_file_opt with
95100
| Some input_file ->
96-
Compile { input_file; output_dir; verbose; generate_makefile; btf_vmlinux_path = btf_path; test_mode }
101+
(* Set default BTF path if none provided *)
102+
let final_btf_path = match btf_path with
103+
| Some path -> Some path
104+
| None -> Some "/sys/kernel/btf/vmlinux"
105+
in
106+
Compile { input_file; output_dir; verbose; generate_makefile; btf_vmlinux_path = final_btf_path; test_mode }
97107
| None ->
98108
printf "Error: No input file specified for compile command\n";
99109
exit 1)

0 commit comments

Comments
 (0)