Monday, March 14, 2011

Japan Earthquake Crisis and Info site in english and Japanese

Japan crisis response page on google http://www.google.com/crisisresponse/japanquake2011.html#resources"

If you wish to donate go to the google page and donate to the japanese red cross.



If your in japan the power will be out in a set schedule around the effected areas as it is diverted to cover the missing power planets

The info is here http://www.tepco.co.jp/index-j.html but the site is very overloaded

The groups are as follows
 第1グループ 6:20~10:00 16:50~20:30 
 第2グループ 9:20~13:00 18:20~22:00
 第3グループ 12:20~16:00 
 第4グループ 13:50~17:30
 第5グループ 15:20~19:00

The number of missing is over 20000, dont be idiots with the sites.

The news is says they are looking for medical staff, medical supplies and portable electric generators.
They are also cooling for basic food water, cooked rice(they need to conserve water) and bread.

The Japanese metorology infomation site lists the series of aftershocks we have had here (as you can see there are over 30).

http://www.jma.go.jp/en/quake/quake_sindo_index.html

Saturday, March 12, 2011

Earthquake Marunouchi building Tokyo Station March 11, 2011



This is the initial quake. On the 19th floor. The buildings seismic meter picked it up as magnitude 4.5. I was in the express elevator on the way up and got kicked out about 10-15 seconds into it, felt like minutes. The sounds you are hearing on the video are the elevators wires and the building walls groaning. The guys you can see are walking back and forth because the building is moving around us like a jumping castle or fair ride. Hence the crappy filming.



This is the first after shock. and im on the 22 flour now. They have continued all night I have counted 6 at least. The buildings seismic meter picked it up as little over magnitude 4. I was back at my desk by this point. The building across the road is about 70-100 meters away. As you can see its moving and we are moving. Not nearly as bad as the first but still its clear to see the effects of quake on a high rise

Tuesday, March 1, 2011

Debuging random segvs

This code is a simple and Focused segv catcher, it is designed for transient and random errors, the ones where you never know when or if they are going to happen. The idea is to use a local varable to scope the monitered area and keep tabs of the last line of code with the jump function. There is a streaming mech to gather input params and other data along the way(ie you can log the local vars in it after the fact). Then when a segv actually happens it wakes up and informs you of where it feel over and what the logged data was.

#include <csignal>
#include <iostream>
#include <stdlib.h>
#include <sstream>
 
namespace SigCatchDebug
{
void (*original)(int);
bool installed = false;
std::string   file_;
int           line_  = 0;

std::stringstream data;

void debug_sig(int type)
{
    if(line_ != 0)
    {
        std::cout << "Signal Caught!!!" << std::endl
                  << "last trace loc:" << file_ << ":" << line_ << std::endl
                  << "----- data was ---- "                     << std::endl
                  << data.str() << std::endl
                  << std::endl;
    }

    if(original != SIG_DFL ||
       original != SIG_IGN)
        (*original)(type);
    
    std::exit(EXIT_FAILURE);  //<<-- this really needs to be here!
}

class AutoScope
{
public:
    AutoScope(const char* file,
              const int   line)
    {
        if(!installed)
        {
            installed = true;

            original = std::signal (SIGSEGV,debug_sig);
            if (original == SIG_ERR)
            {
                std::cout << "signal implosion" << std::endl;
            }            
            //std::cout << "signal installed" << std::endl;
        }
        
        file_        = file;
        line_        = line;

        data.str("");
    }

    template<typename T>
    inline AutoScope& operator<<(const T& t) throw()
    {
        try
        {
            data << t;
        }
        catch (...)
        {}
        return *this;
    }

    ~AutoScope()    
    {
        //std::cout << "signal disable" << std::endl;
        line_ = 0;
    }

    void jump(int line)
    {
        line_ = line;
    }

};

}

void evil_random_crashing_func()
{
    static count = 0;
    char** test = NULL;

    SigCatchDebug::AutoScope sigScope(__FILE__,__LINE__);
    sigScope << "test: " << test << "\n"
             << "count: " << count;

    sigScope.jump(__LINE__);
    if(count == 3)
        test[0] = "ABCDEFG";

    sigScope.jump(__LINE__);
    if(count == 4)
         std::cout << "evil_random_crashing_func: " << test[0] << std::endl;
    
    std::cout << "Evil " << count << std::endl;
    count++;
}

void evil_random_crashing_func2()
{
    char** test = NULL;

    test[0] = "ABCDEFG";
    std::cout << "evil_random_crashing_func2: " << test[0] << std::endl;
}

int main(int argc, char const * const *argv)
{
    try
    {
        evil_random_crashing_func();
        evil_random_crashing_func();
        //evil_random_crashing_func2();
        evil_random_crashing_func();
        evil_random_crashing_func();
        
    }
    catch (std::exception const &e)
    {
        std::cout << "Unexpected exception: " <<  e.what() << std::endl;
    }
    catch (...)
    {
        std::cout << "Unexpected exception" << std::endl;
    }
    return 0;
}

Using dbx to get the contents of the stack on sun machines

Dealing with a coredump created by a transient error. The core is 19GB+. So reproducing it isnt possible. To get the job done i need to get the local vars, param passed in an return value out. To do that I actually have to go to the raw memory dump of the stack and back track it. Here is how

First load your core
dbx exefile corefile

This will get you basic stack demunging.
(dbx) where

This outputs
  [5] __sighndlr(0xb, 0xffffffff6eff8a10, 0xffffffff6eff8730, 0xffffffff7c804c20, 0x0, 0xa), at 0xffffffff752d65b4 
  ---- called from signal handler with signal 11 (SIGSEGV) ------
=>[6] function1(0x0, 0x4, 0x1f, 0xffffffff6eff9518, 0x1029feaf0, 0x2), at 0x100139548 
  [7] function1(0x1029feab0, 0x1f, 0x1003a1, 0x100381000, 0x9000, 0x100000), at 0x1000de2a8
Dbx will guess and print the input params input in the () but keep in mind that the real params maybe passed in the regs so take care.

Jump to the frame you want in my case it was 6, this loads the $sp (stack pointer) and $fp(frame pointer) regs to the correct values. Then dump memory at the $fp
(dbx) frame 6  
(dbx) print -F"%lx" $fp 
  ffffffff6eff8a51
(dbx) examine 0xffffffff6eff8a50  / 100 X   

This produces out like the follow. Now you need to know that the Stack bias is 2047 for 64bit sun machines. Your data starts down the mem dump a bit. For me its down at 0xffffffff6eff8b50-ish:
0xffffffff6eff8a50:      0x00000000 0x00000000 0x00000000 0x00000000
0xffffffff6eff8a60:      0x00000000 0x00000000 0x00000000 0x00000000
0xffffffff6eff8a70:      0x00000000 0x00000000 0x00000000 0x00000000
0xffffffff6eff8a80:      0x00000000 0x00000000 0x00000000 0x00000000
0xffffffff6eff8a90:      0x00000000 0x00000000 0x00000000 0x00000000
0xffffffff6eff8aa0:      0x00000000 0x00000000 0x00000000 0x00000000
0xffffffff6eff8ab0:      0x00000000 0x00000000 0x00000000 0x00000000
0xffffffff6eff8ac0:      0x00000000 0x00000000 0x00000000 0x00000000
0xffffffff6eff8ad0:      0x00000000 0x00000000 0x00000000 0x00000000
0xffffffff6eff8ae0:      0x00000000 0x00000000 0x00000000 0x00000000
0xffffffff6eff8af0:      0x00000000 0x00000000 0x00000000 0x00000000
0xffffffff6eff8b00:      0x00000000 0x00000000 0x00000000 0x00000000
0xffffffff6eff8b10:      0x00000001 0x00263000 0x00000000 0x00000000
0xffffffff6eff8b20:      0x00000000 0x00100263 0x00000000 0x00100000
0xffffffff6eff8b30:      0x00000000 0x0003ea86 0x00000000 0x00000000
0xffffffff6eff8b40:      0x00000000 0x00000000 0x00000000 0x0000001f
0xffffffff6eff8b50:      0x00000000 0x00000000 0x00000000 0x00000004
0xffffffff6eff8b60:      0x00000000 0x0000001f 0xffffffff 0x6eff9518
0xffffffff6eff8b70:      0x00000001 0x029feaf0 0x00000000 0x00000002
0xffffffff6eff8b80:      0xffffffff 0x6eff8a51 0x00000001 0x000de2a8
0xffffffff6eff8b90:      0x00000000 0x00000000 0x00000000 0x00000000
0xffffffff6eff8ba0:      0x00000000 0x07db0301 0x00000000 0x00000000
0xffffffff6eff8bb0:      0x00000000 0x00000000 0x00000000 0x00000000
0xffffffff6eff8bc0:      0x00000000 0x00000000 0x00000000 0x00000000
0xffffffff6eff8bd0:      0x00000000 0x00000000 0x00000000 0x00000000

Then read out the raw mem data and map it to you mem layout the local vars. What a headache right...

For the general stack layout: http://en.wikipedia.org/wiki/Call_stack

For "Stack Bias" Refer to: http://www.shrubbery.net/solaris9ab/SUNWdev/SOL64TRANS/p13.html

Catch 22 using exec in perl forks

I just found a nasty little problem using perl exec.

#!/usr/bin/env perl

my @a = ("sh -c 'asdfsadf ls'", "echo hi", "echo a");

foreach my $b (@a) 
{
    if(fork()==0) 
    {
        exec($b); 
        die "Gahh: $b";
    }
}

print "done\n";

Note what happens when in the case of sub shells and exec:
perl -e "exec('sh -c asdflkj'); die 'gahh';"