Skip to content

Commit

Permalink
Add stacktrace command
Browse files Browse the repository at this point in the history
  • Loading branch information
greeneca committed Mar 5, 2021
1 parent e123147 commit 08e91e4
Showing 1 changed file with 47 additions and 3 deletions.
50 changes: 47 additions & 3 deletions lib/roku_builder/plugins/debuger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ def process_command_response(response)
@threads.each_with_index do |thread, idx|
@logger.unknown "Thread #{idx}: #{thread[:file_path]}"
end
when :stacktrace
stack = response[:data][:stack]
log = "Thread Stack Trace:"
stack.each do |stack_entry|
log += "\n#{stack_entry[:function_name]}: #{stack_entry[:file_path]}(#{stack_entry[:line_number]})"
end
@logger.unknown log
end
end

Expand Down Expand Up @@ -181,6 +188,15 @@ def process_command(command)
else
@logger.error "Unknown Thread #{$1}"
end
when /stacktrace (\d+)/
thread = @threads[$1.to_i]
if @threads and thread
@lock.synchronize do
@socket.send_command(:stacktrace, {thread_index: $1.to_i})
end
else
@logger.error "Unknown Thread #{$1}"
end
else
@logger.warn "Unknown Command: '#{command}'"
end
Expand Down Expand Up @@ -238,17 +254,19 @@ def get_response
response
end

def send_command(command)
def send_command(command, params = nil)
@logger.debug "Sending Command: #{command}"
commands = {
stop: 1,
continue: 2,
threads: 3
threads: 3,
stacktrace: 4
}
size = get_size(command)
send_uint32(size)
send_uint32(@request_id)
send_uint32(commands[command])
send_params(command, params) if params
@active_requests[@request_id.to_s] = command
@request_id += 1
end
Expand All @@ -263,11 +281,23 @@ def get_size(command)
command_size = {
stop: 12,
continue: 12,
threads: 12
threads: 12,
stacktrace: 16
}
return command_size[command]
end

def send_params(command, params)
case command
when :stacktrace
if params[:thread_index]
send_uint32(params[:thread_index])
else
raise IOError, "Missing Param for 'stasktrace' command"
end
end
end

def get_data(command)
case command
when :stop
Expand All @@ -292,6 +322,20 @@ def get_data(command)
data[:threads].push(thread)
end
return data
when :stacktrace
data = {
count: read_uint32,
stack: []
}
data[:count].times do
stack_entry = {
line_number: read_uint32,
function_name: read_utf8z,
file_name: read_utf8z
}
data[:stack].push(stack_entry)
end
return data
end
end

Expand Down

0 comments on commit 08e91e4

Please sign in to comment.