Permalink
Browse files

Merge remote branch 'origin/dyld'

  • Loading branch information...
2 parents 6753ef0 + f055f68 commit 2eb5630aaa27fcfa5e3fe73dd4ecebc627ef8363 @ice799 committed May 18, 2010
Showing with 2,367 additions and 833 deletions.
  1. +16 −0 bin/memprof
  2. +26 −28 ext/elf.c
  3. +11 −5 ext/extconf.rb
  4. +2 −2 ext/i386.h
  5. +52 −0 ext/json.c
  6. +48 −0 ext/json.h
  7. +442 −159 ext/mach.c
  8. +573 −451 ext/memprof.c
  9. +73 −0 ext/mmap.h
  10. +37 −2 ext/tracer.c
  11. +17 −1 ext/tracer.h
  12. +204 −0 ext/tracers/fd.c
  13. +83 −0 ext/tracers/gc.c
  14. +0 −163 ext/tracers/malloc.c
  15. +136 −0 ext/tracers/memcache.c
  16. +210 −0 ext/tracers/memory.c
  17. +87 −0 ext/tracers/mysql.c
  18. +164 −0 ext/tracers/objects.c
  19. +2 −2 ext/tramp.c
  20. +3 −3 ext/x86_gen.c
  21. +0 −13 ext/x86_gen.h
  22. +34 −0 lib/memprof/tracer.rb
  23. +12 −4 spec/memprof_spec.rb
  24. +135 −0 spec/tracing_spec.rb
View
@@ -33,6 +33,22 @@ class MemprofUploader
opts.on("--put-my-data-on-the-internet", "Confirm that you understand\n" +
"memprof.com will show all your \n".rjust(80) +
"internal data on the internet (required)".rjust(80)) {|arg| @confirmed = true}
+ opts.on("--info") do
+ require 'rbconfig'
+ puts RUBY_DESCRIPTION if defined? RUBY_DESCRIPTION
+ puts "CFLAGS='#{Config::CONFIG["CFLAGS"]}' ./configure #{Config::CONFIG["configure_args"]}"
+ bin = "#{Config::CONFIG['bindir']}/#{Config::CONFIG['ruby_install_name']}"
+ puts `file #{bin}`
+
+ if RUBY_PLATFORM =~ /darwin/
+ puts `otool -L #{bin}`
+ else
+ puts `ldd #{bin}`
+ end
+
+ puts
+ exit!
+ end
end
begin
View
@@ -562,32 +562,7 @@ bin_update_image(const char *trampee, struct tramp_st2_entry *tramp, void **orig
/* first check if the symbol is in the PLT */
trampee_addr = find_plt_addr(trampee, NULL);
- /* it isn't in the PLT, try to find it in the binary itself */
- if (!trampee_addr) {
- dbg_printf("Couldn't find %s in the PLT...\n", trampee);
- unsigned char *byte = ruby_info->text_segment;
- trampee_addr = bin_find_symbol(trampee, NULL, 0);
- size_t count = 0;
- int num = 0;
-
- assert(byte != NULL);
-
- if (!trampee_addr) {
- dbg_printf("WARNING: Couldn't find: %s anywhere, so not tramping!\n", trampee);
- return 0;
- }
-
- if (orig_func) {
- *orig_func = trampee_addr;
- }
-
- for(; count < ruby_info->text_segment_len; byte++, count++) {
- if (arch_insert_st1_tramp(byte, trampee_addr, tramp) == 0) {
- num++;
- }
- }
- dbg_printf("Inserted %d tramps for: %s\n", num, trampee);
- } else {
+ if (trampee_addr) {
void *ret = NULL;
dbg_printf("Found %s in the PLT, inserting tramp...\n", trampee);
ret = overwrite_got(trampee_addr, tramp->addr);
@@ -598,6 +573,29 @@ bin_update_image(const char *trampee, struct tramp_st2_entry *tramp, void **orig
*orig_func = ret;
dbg_printf("setting orig function: %p\n", *orig_func);
}
+ } else {
+ trampee_addr = bin_find_symbol(trampee, NULL, 0);
+ dbg_printf("Couldn't find %s in the PLT...\n", trampee);
+
+ if (trampee_addr) {
+ unsigned char *byte = ruby_info->text_segment;
+ size_t count = 0;
+ int num = 0;
+
+ assert(byte != NULL);
+
+ if (orig_func) {
+ *orig_func = trampee_addr;
+ }
+
+ for(; count < ruby_info->text_segment_len; byte++, count++) {
+ if (arch_insert_st1_tramp(byte, trampee_addr, tramp) == 0) {
+ num++;
+ }
+ }
+
+ dbg_printf("Inserted %d tramps for: %s\n", num, trampee);
+ }
}
dbg_printf("Trying to hook %s in other libraries...\n", trampee);
@@ -976,8 +974,8 @@ find_debug_syms(struct elf_info *elf)
dbg_printf(".gnu_debuglink base file name: %s, crc: %lx\n", basename, crc);
dir = dirname(tmp);
- debug_file = malloc(strlen(DEBUGDIR) + strlen(dir) +
- strlen("/") + strlen(basename) + 1);
+ debug_file = calloc(1, strlen(DEBUGDIR) + strlen(dir) +
+ strlen("/") + strlen(basename) + 1);
strncat(debug_file, DEBUGDIR, strlen(DEBUGDIR));
strncat(debug_file, dir, strlen(dir));
View
@@ -33,17 +33,23 @@ def sys(cmd)
sys("tar zxvf #{yajl}")
Dir.chdir("#{dir}/src") do
- FileUtils.mkdir_p "api/yajl"
+ sys("sed -i -e 's,yajl,json,g' *.h *.c api/*.h")
+ Dir['{,api/}yajl*.{h,c}'].each do |file|
+ FileUtils.mv file, file.gsub('yajl', 'json')
+ end
+
+ FileUtils.mkdir_p "api/json"
%w[ common parse gen ].each do |f|
- FileUtils.cp "api/yajl_#{f}.h", 'api/yajl/'
+ FileUtils.cp "api/json_#{f}.h", 'api/json/'
end
File.open("extconf.rb",'w') do |f|
f.puts "require 'mkmf'; $INCFLAGS[0,0] = '-I./api/ '; create_makefile 'libyajl'"
end
- sys("#{Config::CONFIG['bindir']}/#{Config::CONFIG['ruby_install_name']} extconf.rb")
+ sys("#{Config::CONFIG['bindir']}/#{Config::CONFIG['ruby_install_name']} extconf.rb")
sys("make")
+
if RUBY_PLATFORM =~ /darwin/
sys("libtool -static -o libyajl_ext.a #{Dir['*.o'].join(' ')}")
else
@@ -53,15 +59,15 @@ def sys(cmd)
FileUtils.mkdir_p "#{CWD}/dst/lib"
FileUtils.cp 'libyajl_ext.a', "#{CWD}/dst/lib"
FileUtils.mkdir_p "#{CWD}/dst/include"
- FileUtils.cp_r 'api/yajl', "#{CWD}/dst/include/"
+ FileUtils.cp_r 'api/json', "#{CWD}/dst/include/"
end
end
end
$LIBPATH.unshift "#{CWD}/dst/lib"
$INCFLAGS[0,0] = "-I#{CWD}/dst/include "
-unless have_library('yajl_ext') and have_header('yajl/yajl_gen.h')
+unless have_library('yajl_ext') and have_header('json/json_gen.h')
raise 'Yajl build failed'
end
View
@@ -16,8 +16,8 @@ static struct tramp_st2_entry {
unsigned char ret;
} __attribute__((__packed__)) default_st2_tramp = {
.ebx_save = 0x53, /* push ebx */
- .mov = 0xbb, /* mov addr into ebx */
- .addr = 0, /* this is filled in later */
+ .mov = 0xbb, /* mov addr into ebx */
+ .addr = 0, /* this is filled in later */
.call = {0xff, 0xd3}, /* calll *ebx */
.ebx_restore = 0x5b, /* pop ebx */
.ret = 0xc3, /* ret */
View
@@ -0,0 +1,52 @@
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include "json.h"
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+void
+json_gen_reset(json_gen gen)
+{
+ json_gen_clear(gen);
+ assert (gen->state[gen->depth] == json_gen_complete);
+ gen->state[gen->depth] = json_gen_start;
+ gen->print(gen->ctx, "\n", 1);
+}
+
+json_gen_status
+json_gen_cstr(json_gen gen, const char * str)
+{
+ if (!str || str[0] == 0)
+ return json_gen_null(gen);
+ else
+ return json_gen_string(gen, (unsigned char *)str, strlen(str));
+}
+
+json_gen_status
+json_gen_format(json_gen gen, char *format, ...)
+{
+ va_list args;
+ char *str;
+ int bytes_printed = 0;
+
+ json_gen_status ret;
+
+ va_start(args, format);
+ bytes_printed = vasprintf(&str, format, args);
+ assert(bytes_printed != -1);
+ va_end(args);
+
+ ret = json_gen_string(gen, (unsigned char *)str, strlen(str));
+ free(str);
+ return ret;
+}
+
+json_gen_status
+json_gen_pointer(json_gen gen, void* ptr)
+{
+ return json_gen_format(gen, "0x%x", ptr);
+}
View
@@ -0,0 +1,48 @@
+#if !defined(__JSON__H_)
+#define __JSON__H_
+
+#include <stdarg.h>
+#include <json/json_gen.h>
+
+/* HAX: copied from internal json_gen.c (PATCH json before building instead)
+ */
+
+typedef enum {
+ json_gen_start,
+ json_gen_map_start,
+ json_gen_map_key,
+ json_gen_map_val,
+ json_gen_array_start,
+ json_gen_in_array,
+ json_gen_complete,
+ json_gen_error
+} json_gen_state;
+
+struct json_gen_t
+{
+ unsigned int depth;
+ unsigned int pretty;
+ const char * indentString;
+ json_gen_state state[YAJL_MAX_DEPTH];
+ json_print_t print;
+ void * ctx; /* json_buf */
+ /* memory allocation routines */
+ json_alloc_funcs alloc;
+};
+
+/* END HAX
+ */
+
+void
+json_gen_reset(json_gen gen);
+
+json_gen_status
+json_gen_cstr(json_gen gen, const char * str);
+
+json_gen_status
+json_gen_format(json_gen gen, char *format, ...);
+
+json_gen_status
+json_gen_pointer(json_gen gen, void* ptr);
+
+#endif
Oops, something went wrong.

0 comments on commit 2eb5630

Please sign in to comment.