From fa117ee53e8034629deb3e0e1aadb20313f1fb7f Mon Sep 17 00:00:00 2001 From: equivalence1 Date: Mon, 10 Oct 2016 18:40:18 +0300 Subject: [PATCH 1/5] More debug output --- lib/ruby-debug-ide/attach/native_debugger.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ruby-debug-ide/attach/native_debugger.rb b/lib/ruby-debug-ide/attach/native_debugger.rb index d48ed1e..4d9df48 100644 --- a/lib/ruby-debug-ide/attach/native_debugger.rb +++ b/lib/ruby-debug-ide/attach/native_debugger.rb @@ -60,8 +60,8 @@ def get_response content = '' loop do line = @pipe.readline - break if check_delimiter(line) DebugPrinter.print_debug('respond line: ' + line) + break if check_delimiter(line) next if line =~ /\(lldb\)/ # lldb repeats your input to its output content += line end @@ -98,6 +98,7 @@ def continue @pipe.puts 'c' loop do line = @pipe.readline + DebugPrinter.print_debug('respond line: ' + line) break if line =~ /#{Regexp.escape(@tbreak)}/ end get_response From 327fd704fe9bfd2afcfc2444cad5607df4ad835f Mon Sep 17 00:00:00 2001 From: equivalence1 Date: Mon, 17 Oct 2016 15:18:58 +0300 Subject: [PATCH 2/5] More lldb-like breakpoint setting --- lib/ruby-debug-ide/attach/gdb.rb | 6 +++++- lib/ruby-debug-ide/attach/lldb.rb | 6 +++++- lib/ruby-debug-ide/attach/native_debugger.rb | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/ruby-debug-ide/attach/gdb.rb b/lib/ruby-debug-ide/attach/gdb.rb index a507880..1214816 100644 --- a/lib/ruby-debug-ide/attach/gdb.rb +++ b/lib/ruby-debug-ide/attach/gdb.rb @@ -37,11 +37,15 @@ def switch_to_thread(thread_num) execute "thread #{thread_num}" end + def set_break(str) + execute "tbreak #{str}" + end + def call_start_attach super() execute "call dlopen(\"#{@path_to_attach}\", 2)" execute 'call start_attach()' - set_tbreak(@tbreak) + set_break(@tbreak) end def print_delimiter diff --git a/lib/ruby-debug-ide/attach/lldb.rb b/lib/ruby-debug-ide/attach/lldb.rb index 87245df..5d301d2 100644 --- a/lib/ruby-debug-ide/attach/lldb.rb +++ b/lib/ruby-debug-ide/attach/lldb.rb @@ -35,11 +35,15 @@ def switch_to_thread(thread_num) execute "thread select #{thread_num}" end + def set_break(str) + execute "breakpoint set --shlib #{@path_to_attach} --name #{str}" + end + def call_start_attach super() execute "expr (void *) dlopen(\"#{@path_to_attach}\", 2)" execute 'expr (int) start_attach()' - set_tbreak(@tbreak) + set_break(@tbreak) end def print_delimiter diff --git a/lib/ruby-debug-ide/attach/native_debugger.rb b/lib/ruby-debug-ide/attach/native_debugger.rb index 4d9df48..852d5a4 100644 --- a/lib/ruby-debug-ide/attach/native_debugger.rb +++ b/lib/ruby-debug-ide/attach/native_debugger.rb @@ -89,8 +89,8 @@ def switch_to_thread end - def set_tbreak(str) - execute "tbreak #{str}" + def set_break(str) + end def continue From 68e87533a2268cf0bccc31f3b164e8125caee507 Mon Sep 17 00:00:00 2001 From: equivalence1 Date: Mon, 17 Oct 2016 15:22:35 +0300 Subject: [PATCH 3/5] Proper extension added --- lib/ruby-debug-ide/attach/native_debugger.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ruby-debug-ide/attach/native_debugger.rb b/lib/ruby-debug-ide/attach/native_debugger.rb index 852d5a4..cda6876 100644 --- a/lib/ruby-debug-ide/attach/native_debugger.rb +++ b/lib/ruby-debug-ide/attach/native_debugger.rb @@ -30,7 +30,7 @@ def initialize(executable, pid, flags, gems_to_include, debugger_loader_path, ar def find_attach_lib(debase_path) attach_lib = debase_path + '/attach' - known_extensions = %w(.so .bundle .dll) + known_extensions = %w(.so .bundle .dll .dylib) known_extensions.each do |ext| if File.file?(attach_lib + ext) return attach_lib + ext From dc009872a7073c608ce1e98a9f55068248a4e548 Mon Sep 17 00:00:00 2001 From: equivalence1 Date: Mon, 17 Oct 2016 15:28:11 +0300 Subject: [PATCH 4/5] C extension for attach already moved to debase gem --- ext/Makefile | 10 ---------- ext/attach.c | 29 ----------------------------- ext/attach.h | 9 --------- 3 files changed, 48 deletions(-) delete mode 100644 ext/Makefile delete mode 100644 ext/attach.c delete mode 100644 ext/attach.h diff --git a/ext/Makefile b/ext/Makefile deleted file mode 100644 index 6c52c90..0000000 --- a/ext/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -all: libAttach.so - -libAttach.so: libAttach.o - gcc -shared -o libAttach.so libAttach.o - -libAttach.o: attach.c - gcc -Wall -g -fPIC -c -I/home/equi/.rvm/rubies/ruby-2.3.1/include/ruby-2.3.0 -I/home/equi/.rvm/rubies/ruby-2.3.1/include/ruby-2.3.0/x86_64-linux/ attach.c -o libAttach.o - -clean: - rm libAttach.* diff --git a/ext/attach.c b/ext/attach.c deleted file mode 100644 index d4d4dbe..0000000 --- a/ext/attach.c +++ /dev/null @@ -1,29 +0,0 @@ -#include "attach.h" - -static void -__func_to_set_breakpoint_at() -{ -} - -static void -__catch_line_event(rb_event_flag_t evflag, VALUE data, VALUE self, ID mid, VALUE klass) -{ - (void)sizeof(evflag); - (void)sizeof(self); - (void)sizeof(mid); - (void)sizeof(klass); - - rb_remove_event_hook(__catch_line_event); - if (rb_during_gc()) - return; - __func_to_set_breakpoint_at(); -} - -int -start_attach() -{ - if (rb_during_gc()) - return 1; - rb_add_event_hook(__catch_line_event, RUBY_EVENT_LINE, (VALUE) NULL); - return 0; -} diff --git a/ext/attach.h b/ext/attach.h deleted file mode 100644 index 9c98192..0000000 --- a/ext/attach.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef __ATTACH_H__ -#define __ATTACH_H__ - -#include -#include - -int start_attach(); - -#endif //__ATTACH_H__ \ No newline at end of file From 17e92ecfd75f3f4c0829f5371705ad2b1e25afc2 Mon Sep 17 00:00:00 2001 From: equivalence1 Date: Fri, 28 Oct 2016 01:39:23 +0300 Subject: [PATCH 5/5] Changed `start_attach` function name in debase. Added wrapper function `debase_rb_eval` in debase --- lib/ruby-debug-ide/attach/gdb.rb | 2 +- lib/ruby-debug-ide/attach/lldb.rb | 4 ++-- lib/ruby-debug-ide/attach/native_debugger.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ruby-debug-ide/attach/gdb.rb b/lib/ruby-debug-ide/attach/gdb.rb index 1214816..bf9085c 100644 --- a/lib/ruby-debug-ide/attach/gdb.rb +++ b/lib/ruby-debug-ide/attach/gdb.rb @@ -44,7 +44,7 @@ def set_break(str) def call_start_attach super() execute "call dlopen(\"#{@path_to_attach}\", 2)" - execute 'call start_attach()' + execute 'call debase_start_attach()' set_break(@tbreak) end diff --git a/lib/ruby-debug-ide/attach/lldb.rb b/lib/ruby-debug-ide/attach/lldb.rb index 5d301d2..b9bdc31 100644 --- a/lib/ruby-debug-ide/attach/lldb.rb +++ b/lib/ruby-debug-ide/attach/lldb.rb @@ -42,7 +42,7 @@ def set_break(str) def call_start_attach super() execute "expr (void *) dlopen(\"#{@path_to_attach}\", 2)" - execute 'expr (int) start_attach()' + execute 'expr (int) debase_start_attach()' set_break(@tbreak) end @@ -55,7 +55,7 @@ def check_delimiter(line) end def load_debugger - execute "expr (VALUE) #{@eval_string}" + execute "expr (void) #{@eval_string}" end def to_s diff --git a/lib/ruby-debug-ide/attach/native_debugger.rb b/lib/ruby-debug-ide/attach/native_debugger.rb index cda6876..87eebc9 100644 --- a/lib/ruby-debug-ide/attach/native_debugger.rb +++ b/lib/ruby-debug-ide/attach/native_debugger.rb @@ -21,7 +21,7 @@ def initialize(executable, pid, flags, gems_to_include, debugger_loader_path, ar @debugger_loader_path = debugger_loader_path @argv = argv - @eval_string = "rb_eval_string_protect(\"require '#{@debugger_loader_path}'; load_debugger(#{@gems_to_include.gsub("\"", "'")}, #{@argv.gsub("\"", "'")})\", (int *)0)" + @eval_string = "debase_rb_eval(\"require '#{@debugger_loader_path}'; load_debugger(#{@gems_to_include.gsub("\"", "'")}, #{@argv.gsub("\"", "'")})\", (int *)0)" launch_string = "#{self} #{executable} #{flags}" @pipe = IO.popen(launch_string, 'r+')