Re: [Ekiga-devel-list] I need brains!



Hi,

here is the source of a backtrace dumper to follow each and every gmref_inc/gmref_dec in ekiga (and can print "THIS:" for objects of interest though that is commented out).

It uses nemiver-as-a-lib (needs svn from nemiver and snapshot from gdb, and the target program can't print anything on console -- gdb bug).

Snark
#include <iostream>
#include <glibmm.h>

#include <common/nmv-initializer.h>
#include <common/nmv-safe-ptr-utils.h>
#include <dynmods/nmv-i-debugger.h>

using namespace nemiver;
using namespace nemiver::common;

Glib::RefPtr<Glib::MainLoop> loop = Glib::MainLoop::create(Glib::MainContext::get_default ());

static void
on_signal_received_signal (const UString& msg,
			   const UString& cookie)
{
  std::cerr << "SIGNAL: " << msg << std::endl;
}

static void
on_error_signal (const UString& message,
		 IDebuggerSafePtr& debugger)
{
  debugger->do_continue ();
}

static void
on_variable_value_signal (const UString& name,
			  const IDebugger::VariableSafePtr& variable,
			  const UString& cookie,
			  IDebuggerSafePtr& debugger)
{
  if (name == "this") {

    std::cerr << "THIS: " << variable->value () << std::endl;
    debugger->do_continue ();
  } else if (name == "obj") {

    debugger->list_frames (variable->value ());
  }  else {

    debugger->do_continue ();
  }
}

static void
on_frames_listed_signal (const vector<IDebugger::Frame> frames,
			 const UString& obj,
			 IDebuggerSafePtr& debugger)
{
  std::cout << "Backtrace:" << std::endl;
  vector<IDebugger::Frame>::const_iterator iter = frames.begin ();
  std::cout << "\t" << iter->function_name () << " " << obj << std::endl;
  ++iter;
  for ( /* nothing */ ;
       iter != frames.end ();
       ++iter)
    std::cout << "\t" << iter->function_name () << std::endl;
  std::cout.flush ();
  debugger->do_continue ();
}

static void
on_stopped_signal (IDebugger::StopReason a_reason,
		   bool has_frame,
		   const IDebugger::Frame& frame,
		   int thread_id,
		   int breakpoint_number,
		   const UString& cookie,
		   IDebuggerSafePtr& debugger)
{
  switch (a_reason) {

  case IDebugger::BREAKPOINT_HIT:

    if (has_frame) {

      if (frame.function_name () == "gmref_inc"
	  || frame.function_name () == "gmref_dec") {

	debugger->print_variable_value ("obj");
      } else
	debugger->print_variable_value ("this");
    }
    break;

  default:
    loop->quit ();
  }
}

int
main (int argc,
      char* argv[])
{

  NEMIVER_TRY

  Initializer::do_init ();

  DynamicModuleManager module_manager ;
  IDebuggerSafePtr debugger = module_manager.load_iface<IDebugger> ("gdbengine", "IDebugger");

  debugger->set_event_loop_context (loop->get_context ());
  std::vector<UString> args;
  std::vector<UString> source_search_dir;

  source_search_dir.push_back (".");
  args.push_back (argv[1]);

  debugger->error_signal ().connect (sigc::bind (&on_error_signal, debugger));

  debugger->stopped_signal ().connect (sigc::bind (&on_stopped_signal,
  						   debugger));

  debugger->frames_listed_signal ().connect (sigc::bind (&on_frames_listed_signal, debugger));

  debugger->variable_value_signal ().connect (sigc::bind (&on_variable_value_signal, debugger));

  debugger->signal_received_signal ().connect (&on_signal_received_signal);

  debugger->load_program (args, "", source_search_dir);

  //debugger->set_breakpoint ("avahi-heap.cpp", 91);
  //debugger->set_breakpoint ("local-heap.cpp", 52);
  debugger->set_breakpoint ("gmref_inc");
  debugger->set_breakpoint ("gmref_dec");

  debugger->run ();
  loop->run ();

  NEMIVER_CATCH_AND_RETURN_NOX (-1)

  return 0;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]