Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

osx fixes

  • Loading branch information...
commit 274cca4b6978583def35df9f3df0f20de54d26c5 1 parent e8877cb
@tduehr authored
View
51 examples/hittracerx.rb
@@ -4,7 +4,8 @@
# FILE is CSV file,address
# PID is the proces id to attach to.
-require 'debuggerosx'
+require 'rubygems'
+require 'ragweed'
require 'pp'
require 'irb'
include Ragweed
@@ -12,10 +13,18 @@
filename = ARGV[0]
pid = ARGV[1].to_i
-raise "hittracerosx.rb FILE PID" if (ARGV.size < 2 or pid <= 0)
+raise "hittracerx.rb FILE PID" if (ARGV.size < 2 or pid <= 0)
+
+class HitTracer < Ragweed::Debuggerosx
+ attr_accessor :counts
+
+ def initialize(*args)
+ @counts = Hash.new(0)
+ super
+ end
-class Debuggerosx
def on_exit
+ pp @counts
exit(1)
end
@@ -25,39 +34,51 @@ def on_single_step
def on_segv(thread)
pp self.get_registers(thread)
pp self.threads
- self.threads.each {|thread| puts Wraposx::ThreadContext.get(thread).dump}
- self.threads.each {|thread| puts Wraposx::ThreadInfo.get(thread).dump}
+ self.threads.each {|thread| puts self.get_registers(thread).dump}
+ self.threads.each {|thread| puts Ragweed::Wraposx::thread_info(thread, Ragweed::Wraposx::ThreadInfo::BASIC_INFO).dump}
throw(:break)
end
def on_bus(thread)
+ puts "BUS!"
throw(:break)
end
end
-d = Debuggerosx.new(pid)
+d = HitTracer.new(pid)
d.attach
+puts "attached"
+
File.open(filename, "r") do |fd|
- lines = fd.readlines
- lines.map {|x| x.chomp}
- lines.each do |tl|
- fn, addr = tl.split(",", 2)
- d.breakpoint_set(addr.to_i(16), fn, (bpl = lambda do | t, r, s | puts "#{ s.breakpoints[r.eip].first.function } hit in thread #{ t }\n"; end))
+ fd.each_line do |tl|
+ fn, addr = tl.split(",", 2).map{|x| x.strip}
+ pp [fn, addr.to_i(16).to_s(16)]
+ d.breakpoint_set(addr.to_i(16), fn, (bpl = lambda do | tid, regs, slf |
+ puts "#{ slf.breakpoints[regs.eip].first.function } hit in thread #{ tid }\n"
+ d.counts[slf.breakpoints[regs.eip].first.function] += 1
+ end))
end
end
+puts "breakpoints loaded"
+
d.install_bps
+puts "breakpoints installed"
d.continue
-catch(:throw) { d.loop }
+puts "continued"
+catch(:throw) { d.loop(nil) }
+puts 'thrown'
pp d.wait 1
pp d.threads
-d.threads.each do |t|
- r = Wraposx::ThreadContext.get(t)
- i = Wraposx::ThreadInfo.get(t)
+d.threads.each do |tid|
+ r = d.get_registers(tid)
+ i = Wraposx::thread_info(tid, Wraposx::ThreadInfo::BASIC_INFO)
pp r
puts r.dump
pp i
puts i.dump
end
+
+
View
3  lib/ragweed/debuggerosx.rb
@@ -180,7 +180,6 @@ def on_detach
# Fired when single stepping at every step
# Not currently used in OSX
def on_single_step
- #puts Ragweed::Wraposx::ThreadInfo.get(thread).inspect
end
# Called with the child process's status on exit
@@ -257,7 +256,7 @@ def hook(opts=@opts)
self.attach(opts) if opts[:attach] and not @attached
return @task
end
- alias hook attach_mach
+ alias attach_mach hook
# theoretically to close the task port but,
# no way to close the port has yet been found.
View
8 lib/ragweed/wraposx/thread_context.rb
@@ -355,6 +355,14 @@ def respond_to? meth, include_priv=false
self.methods.include? mth || super
end
+ def dump(&block)
+ case self[:tsh][:flavor]
+ when Ragweed::Wraposx::ThreadContext::X86_THREAD_STATE32
+ self[:uts][:ts32].dump(&block)
+ when Ragweed::Wraposx::ThreadContext::X86_THREAD_STATE64
+ self[:uts][:ts64].dump(&block)
+ end
+ end
end
# _STRUCT_X86_DEBUG_STATE32
View
6 lib/ragweed/wraposx/thread_info.rb
@@ -142,6 +142,12 @@ def dump(&block)
end
module Ragweed::Wraposx
+ module Libc
+ extend FFI::Library
+ ffi_lib FFI::Library::LIBC
+ attach_function :thread_info, [:thread_act_t, :thread_flavor_t, :pointer, :pointer], :kern_return_t
+ end
+
class << self
# Returns the thread_info_t struct.
View
3  lib/ragweed/wraposx/wraposx.rb
@@ -23,6 +23,7 @@ module Libc
typedef :int, :policy_t
typedef :int, :boolean_t
typedef :int, :thread_state_flavor_t
+ typedef :int, :thread_flavor_t
case FFI::Platform::LONG_SIZE
when 64
# ifdef __LP64__
@@ -47,7 +48,7 @@ module Libc
attach_function :task_threads, [:task_t, :pointer, :pointer], :kern_return_t
attach_function :kill, [:pid_t, :int], :int
attach_function :vm_read_overwrite, [:vm_map_t, :vm_address_t, :vm_size_t, :pointer, :pointer], :kern_return_t
- attach_function :vm_write, [:vm_map_t, :vm_address_t, :vm_offset_t, :mach_msg_type_number_t], :kern_return_t
+ attach_function :vm_write, [:vm_map_t, :vm_address_t, :pointer, :mach_msg_type_number_t], :kern_return_t
attach_function :vm_protect, [:vm_map_t, :vm_address_t, :vm_size_t, :boolean_t, :vm_prot_t], :kern_return_t
attach_function :vm_allocate, [:vm_map_t, :pointer, :vm_size_t, :int], :kern_return_t
attach_function :vm_deallocate, [:vm_map_t, :vm_address_t, :vm_size_t], :kern_return_t
Please sign in to comment.
Something went wrong with that request. Please try again.