Skip to content

Commit d91c3d1

Browse files
equivalence1dmitrii.kravchenko
authored andcommitted
added debug output if --debug key specified.
1 parent 7a15fac commit d91c3d1

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

bin/gdb_wrapper

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,30 @@ options = OpenStruct.new(
1313
'gems_to_include' => []
1414
)
1515

16+
module DebugPrinter
17+
18+
class << self
19+
attr_accessor :cli_debug
20+
21+
def print_debug(msg)
22+
if DebugPrinter.cli_debug
23+
delimiter = '=' * 10
24+
upper_border = "\n#{delimiter}\n"
25+
lower_border = "#{delimiter}\n\n"
26+
27+
if msg.length > 0 and msg[msg.length - 1] != "\n"
28+
lower_border = "\n" + lower_border
29+
end
30+
31+
$stdout.puts upper_border + msg + lower_border
32+
end
33+
end
34+
end
35+
36+
end
37+
38+
DebugPrinter.cli_debug = ARGV.include? '--debug'
39+
1640
opts = OptionParser.new do |opts|
1741
# TODO need some banner
1842
opts.banner = <<EOB
@@ -110,6 +134,9 @@ class NativeDebugger
110134
break if line =~ /\$\d+\s=\s"#{@delimiter}"/
111135
content += line
112136
end
137+
138+
DebugPrinter.print_debug(content)
139+
113140
content
114141
end
115142

@@ -317,7 +344,13 @@ class ProcessThread
317344
end
318345

319346
def command_exists(command)
347+
checking_command = "checking command #{command} for existence\n"
320348
`command -v #{command} >/dev/null 2>&1 || { exit 1; }`
349+
if $?.exitstatus != 0
350+
DebugPrinter.print_debug("#{checking_command}command does not exist.")
351+
else
352+
DebugPrinter.print_debug("#{checking_command}command does exist.")
353+
end
321354
$?.exitstatus == 0
322355
end
323356

@@ -348,6 +381,7 @@ debugger.attach_to_process
348381
debugger.set_flags
349382

350383
if options.uid
384+
DebugPrinter.print_debug("changing current uid from #{Process.uid} to #{options.uid}")
351385
Process::Sys.setuid(options.uid.to_i)
352386
end
353387

0 commit comments

Comments
 (0)