Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attach to child processes #108

Merged
merged 3 commits into from
Aug 7, 2017

Conversation

ViugiNick
Copy link
Collaborator

No description provided.

Copy link
Contributor

@valich valich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the comments below. The code in gdb_wrapper is too cluttered with some technical consequences, too. Please fix.

pids
end

def reset_port(argv)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't get the purpose of that method. I feel uncomfortable with re-checking argv values once again when you have an appropriate library for that.
And also, mutating the parameter container is a bad practice.

Copy link
Collaborator Author

@ViugiNick ViugiNick Jul 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case argv is transferred to rdebug as a string in load_debugger method

pid = q.pop
pids << pid

if(command_exists 'pgrep')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're checking for the command presence each time, does it mean that the command may disappear during children collection? If not, process such check beforehand and, ideally, also incapsulate running external processes into a separate method(s) in order to fix possible related bugs in a dedicated place.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the command does not exist, then only one element will be added to the queue and the check will be performed once. But it does not look very nice, I agree

q = Queue.new
q.push(pid)

while(!q.empty?) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing (here and after)

bin/gdb_wrapper Outdated
end
end
debugger.exit
pids.each_with_index do |pid, i|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of nested methods deserve method extraction. Please split the code into sensible methods

bin/gdb_wrapper Outdated
debugger.exit
pids.each_with_index do |pid, i|

if(i == 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the extraction of the logic below into methods this each_with_index and if i == ..., which are not beautiful, could be transformed to normal logic like "do something with the parent process and do something else with all its children" without any additional overhead.

bin/gdb_wrapper Outdated

debugger.attach_to_process
debugger.set_flags
attach_threads << Thread.new(argv) do |argv|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another possible way to do this is to replace each with map and then just chain call the result.

bin/gdb_wrapper Outdated
DebugPrinter.print_debug("changing current uid from #{Process.uid} to #{options.uid}")
Process::Sys.setuid(options.uid.to_i)
end
debugger = choose_debugger(options.ruby_path, options.gems_to_include, debugger_loader_path, argv)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of removing pid as a instance variable of a NativeDebugger? Also, does it work at all if one attaches from multiple processes to one ruby executable?

Copy link
Contributor

@valich valich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better, thanks. Still I have a couple of concerns :)

def get_child_pids(pid)
pids = Array.new

if (!command_exists 'pgrep')
return pids
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return [] unless command_exists

bin/rdebug-ide Outdated
@@ -60,6 +60,9 @@ EOB
opts.on("--attach-mode", "Tells that rdebug-ide is working in attach mode") do
options.attach_mode = true
end
opts.on("--attach-child", "child process for attach") do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this explanation is not clear. If I understand the intent correctly, this param defines whether current process is somebody's child thus should not use port setting. Maybe --ignore-port?

bin/gdb_wrapper Outdated
@@ -65,7 +65,7 @@ unless options.ruby_path
exit 1
end

argv = '["' + ARGV * '", "' + '"]'
argv = '["' + ARGV * '", "'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think precalculating this part of argv (and creating such variable) is not really needed

def attach_to_process(pid)
execute "attach #{pid}"
def attach_to_process
execute "attach #{@pid}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still I believe pid must be specified in executable when running gdb/lldb. AFAIR you've said yourself it does not work otherwise?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For gdb your approach doesn't work without '-p' before the pid, so we have to use a different implementation for lldb and gbd. Therefore, it seems to me that it is better to leave it as it is

@valich valich merged commit 4333f10 into ruby-debug:master Aug 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants