Add a "-d time" option to stack_dump to dump the stack at the given time.
diff --git a/emulator/qtools/stack_dump.cpp b/emulator/qtools/stack_dump.cpp
index b5014ef..35ee61c 100644
--- a/emulator/qtools/stack_dump.cpp
+++ b/emulator/qtools/stack_dump.cpp
@@ -15,6 +15,9 @@
 #include "parse_options-inl.h"
 #include "callstack.h"
 
+static uint64_t debugTime;
+static uint64_t dumpTime = 0;
+
 class MyFrame : public StackFrame<symbol_type> {
   public:
     void    push(int stackLevel, uint64_t time, CallStackBase *base);
@@ -25,6 +28,8 @@
 
 void MyFrame::push(int stackLevel, uint64_t time, CallStackBase *base)
 {
+    if (dumpTime > 0)
+        return;
     printf("%llu en thr %d %3d", time, base->getId(), stackLevel);
     for (int ii = 0; ii < stackLevel; ++ii)
         printf(".");
@@ -33,6 +38,8 @@
 
 void MyFrame::pop(int stackLevel, uint64_t time, CallStackBase *base)
 {
+    if (dumpTime > 0)
+        return;
     printf("%llu x  thr %d %3d", time, base->getId(), stackLevel);
     for (int ii = 0; ii < stackLevel; ++ii)
         printf(".");
@@ -43,8 +50,6 @@
 static const int kMaxThreads = (32 * 1024);
 CallStackType *stacks[kMaxThreads];
 
-static uint64_t debugTime;
-
 void Usage(const char *program)
 {
     fprintf(stderr, "Usage: %s [options] trace_name elf_file\n",
@@ -52,9 +57,29 @@
     OptionsUsage();
 }
 
+bool localParseOptions(int argc, char **argv)
+{
+    bool err = false;
+    while (!err) {
+        int opt = getopt(argc, argv, "+d:");
+        if (opt == -1)
+            break;
+        switch (opt) {
+        case 'd':
+            dumpTime = strtoull(optarg, NULL, 0);
+            break;
+        default:
+            err = true;
+            break;
+        }
+    }
+    return err;
+}
+
 int main(int argc, char **argv)
 {
     ParseOptions(argc, argv);
+    localParseOptions(argc, argv);
     if (argc - optind != 2) {
         Usage(argv[0]);
         exit(1);
@@ -66,9 +91,6 @@
     trace->Open(qemu_trace_file);
     trace->ReadKernelSymbols(elf_file);
     trace->SetRoot(root);
-    TraceHeader *qheader = trace->GetHeader();
-    uint64_t startTime = qheader->start_sec;
-    startTime = (startTime << 32) | qheader->start_usec;
 
     BBEvent event;
     while (1) {
@@ -93,6 +115,13 @@
 
         // Update the stack
         pStack->updateStack(&event, function);
+
+        // If the user requested a stack dump at a certain time,
+        // and we are at that time, then dump the stack and exit.
+        if (dumpTime > 0 && event.time >= dumpTime) {
+            pStack->showStack(stdout);
+            break;
+        }
     }
 
     for (int ii = 0; ii < kMaxThreads; ++ii) {