Thursday, April 08, 2010

Stacktrace forencis

Many a times you would find the stacktrace ( through pstack or stacktrace files from production) supplied for finding the root cause. There's lot much information you can extract from stack-trace, here’s a summary from my experience in debugging core files.

  1. The faulty stack frame

You could pin point the faulty stack frame by looking at the backtrace file, you would see that all the stack-frames (barring one) are under wait (by executing blocking syscall e.g lwp_park or nanosleep et. al). As you know only one context would be in execution and you can identify it by looking at the last call.

Below is an extract of one such faulty stack frame

----------------- lwp# 9 / thread# 9 --------------------

fe241dd0 waitid (0, 22ac, f2372470, 3)

fe234bfc waitpid (22ac, f23725c4, 0, 0, f237261c, fe162b00) + 60

fe22828c system (f237275c, fe272034, 20000, 1, fe26a2b4, f237261c) + 2ec

fe54094c void MyApplication::generateStackTraceFile(MyModule::AppMgrId,long,const char*,bool) (f23728ac, 41c, 20fbc8, f23728ac, fe703c18, fe755050) + 42c

fe5404a4 void MyApplication::fatalSignal(int) (0, fe755050, 211f88, fe758db4, 388, 0) + 5c

fe240a14 __sighndlr (b, 0, f2372c90, fe540448, 0, 1) + c

fe235a30 call_user_handler (b, 0, 0, 100, fd3e1800, f2372c90) + 3b8

fe224220 fileno (0, 7c, ff11f728, ff11d3f4, 2881c, ff11efc4)

0004036c bool FileSender::sendPoll(unsigned short,MyAppEnum::RedEnum,int,unsigned short,unsigned long) (1, 8000, d213b, f2376ddc, 1a1400, 0) + db8

00059504 void FileSender::sendScPoll() (128430, 2affc227, 102024, 16e454, f237886c, 15f000) + f4

......
......

fe54d134 void*BaseThread::execute(void*) (604a08, 3b8, fe755050, 0, 108, 0) + 68

fe2408e8 _lwp_start (0, 0, 0, 0, 0, 0)

----------------- lwp# 10 / thread# 10 --------------------

  1. Identifying the last user-space function call

You could see from the stack trace that the last user space API looks like MyApplication::generateStackTraceFile, which is correct, but this is not the probable faulty function responsible for the crash, as this method is generating the trace-back file, this means that the ‘fatal signal’ was raised somewhere down the stack. So, we look down at the stack and see that ‘sendPoll’ is the previous user-space function call. ‘fineno’, call_uesr_handler, __sighndlr are either kernel space or libc based api’s, so we wouldn’t bother about them.

  1. Reaching the last statement within the function to pin-point the probable cause of crash.

This is a little trick part. One straight forward way is to attach a debugger to the core, and feel lucky that the core is ‘not corrupt' and you see the line.no. displayed using ‘where’ command, many a times the core is not available and all you have is a stacktrace file from production. If such a case the following information would be useful.

0004036c bool FileSender::sendPoll(unsigned short,MyAppEnum::RedEnum,int,unsigned short,unsigned long) (1, 8000, d213b, f2376ddc, 1a1400, 0) + db8

We pick the function call FileSender::sendPoll and see that there’s an offset db8 mentioned in the stack-trace, this means that the last instruction that caused this process to crash was at an offset of db8 bytes from the starting of the function FileSender::sendPoll

Next steps is to reach at this offset. Unfortunately, we can’t look at the C++ code to determine the bytes offset. What we need to do is compile the corresponding source file to generate an assembly code. On solaris we use SUN’s ‘CC’ compiler, and the corresponding compiler option to generate the assembly code is -S

  1. Generating assembly code file for a given source file

Use your compiler's 'generate assembly' switch to generate the code. Something like

bash-3.00$ pwd

/home/skp/cmp/obj/......./

bash-3.00$ ls -l FileSender.s

-rw-rw-r-- 1 skp staff 6640175 Mar 10 12:56 FileSender.s

  1. Moving to the offset with-in the function

Now that we have the assembled code, we can go the required offset. I’m listing down the assembled code. The code generated through –S option would have mangled symbols, to de-mangle them you could use c++filt as below

bash-3.00$ c++filt FileSender.s > FileSender_dem.s

! SUBROUTINE bool FileSender::sendPoll(unsigned short,MyAppEnum::RedEnum,int,unsigned short,unsigned long)

!

! OFFSET SOURCE LINE LABEL INSTRUCTION

......

......

bool FileSender::sendPoll(unsigned short,MyAppEnum::RedEnum,int,unsigned short,unsigned long):

/* 000000 2167 */ sethi %hi(0x4c00),%g1

………………….. .

…………………..

…………………..

Now keep moving down till we move to an offset of db8, meaning thereby, that we’ll have to reach an address of 0x0000 + 0x0db8 = 0x0db8

Following line gives the corresponding offset listing

/* 0x0db8 2286 */ call pclose ! params = %o0 ! Result =

Which shows that the last line caused this process to generate ‘fatal signal’ was pclose. The above line shows that the offset was 0x0db8 and corresponding line number within the C++ file is 2286

  1. Reviewing the equivalent code

2282 FILE* fd=popen(command,"w");

2283 if (fd == NULL){

2284 Logger.logMsg(MyAppTrace::ERROR,"Fail to execute ");//check for log, if you are luck you might see this log

2285 }

2286 pclose(fd); // this might result in SIGSEGV if fd is NULL

  1. Which signal might have caused the crash.

Again we revert back to the stacktrace, it shows

fe235a30 call_user_handler (b, 0, 0, 100, fd3e1800, f2372c90) + 3b8

as one of the calls. A little googling shows that this is a kernel space api that calls the ‘callback’ signal handler and its first argument is the signal number. Which is b, meaning 11 (SIGSEGV)

bash-3.00$ kill -l

1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL

5) SIGTRAP 6) SIGABRT 7) SIGEMT 8) SIGFPE

9) SIGKILL 10) SIGBUS 11) SIGSEGV 12) SIGSYS


This confirms our debugging and we can provide the corresponding fix.

Hope this is helpful to many how are into debugging stufff.

Wednesday, September 16, 2009

Meet KUKU









Meet Kuku. I wouldn't write much about kuku, lest Kuku would offended. Kuku is the result of Anoop [ contactanuptop at gmail dot com ] and My creative endeavor.
Do spare some time to put your comments.

Monday, March 03, 2008

Zen & The Art of Cracking PJ

There will always be debate whether Great “PJayers” are born or made. If you happen to meet any such “PJayer“, you would never be asking that question again. If you are still in dilemma, then, hang-on a bit, you would know. Let me make things easier for some buddying “PJayers” (As if I’m the greatest ‘un). Great “PJayers” are born with this superlative skill. And let me tell you…..most of you already have it embedded in you (you just need to hone your skills and find a coterie, that would not banish you for your initial hiccups).

On the hind side, people who have always considered themselves to be on the lower rung of “PJness” ladder shouldn’t feel bad. You always have a chance to germinate this greatness in the tiniest of your living tissues. All you need is a sense of confidence, endurance and a bit (not even a Byte [bad one ‘huh]) of humor. I’m sure with your daily dose of humiliation, among the best (and not so best) of your friends, you would come out to be a real gem. And, if you are still not able to cope with the strong competition posed by all the buddying “PJayers” of your group!! be calm & quite till you find your savior.

Having said that, it becomes my earnest duty to tell all the “PJay” practitioners, who are striving to reach the top, few salient points about “how to crack those quick ones”. It might sound a bit complicated, in reality…. it is COMPLICATED. Before we start with the hands on, let me throw some pointers on the characteristics of a GOOD PJ.

1. “PJays” are serious thoughts.

2. “PJays” are seriously ILLOGICAL, but, convey the ambiguity in the plain logic.

3. “PJays” are furtive. They are like those stinkers which make their presence felt in a big gathering, without anyone noticing the source of them.

4. The effectiveness of any “PJay“ can be accessed by looking at the expression exuded by its listeners. More the laughing faces, the bad is your “PJay“.

5. “PJays” are short. In physical terms, humor generated by a “PJay” is inversely proportional to the length of the “PJay. A word of caution, there might be some side effects (like “PJayer” getting a harsh/physical treatment) if the length is increased beyond a certain point. Try with small ones like “Ramu is very happy today, his kid started speaking A B C D in english”.

Alrighty!! enough of theory now. I’m sure all the initiators must be raring to get their hands dirty. Here’s what you need to do on your first “conscious” attempt to “PJaying“.

1. Wear some bump protecting gear, like two/three pair of trousers or a superman kit. That would really help if anything goes wrong.

2. Have few dozen chocolates in your pockets, so that, you could always spill them to save your soul when you, kind of, violate the limit of patience of your buddies.

3. Try to crack your initial “PJays” in OPEN, that would give you ample space to run away, in case you shockingly surprise your peers.

All the above points would make you fairly secure to go full on to crack, crackle-crackle, your “PJays“. When you succeed to make initial in-roads into the psyche of your buddies, you would gain some confidence. This is a critical juncture of your practice. Treat this confidence as your support and do not get over confident (it could just be the generosity of your friends, that they didn’t really beat you up). Like they say,”Slow and Study Wins The Race”. Try increasing the count of your “PJays” by 2 on a daily basis. I’m sure with a bit of Gods grace you would see yourself through. And when you are through this phase, you would have earned yourself a reputation which would surpass the wildest of your imagination. Now, is the time to unleash your wittiest & wackiest ones.

I guess this much of assistance should suffice to head start your journey to perfection.
I hope with a bit of caution and innovation you would conquer the worst of difficulties to come out a real “PJayer“.

Remember!! “it requires a PJayer to be a PJayer” (what does that mean??), it means “it requires a PJayer to be a PJayer”. You can’t be “Atal Bihari Vajpayee” to speak like “Lalu Prasad Yadav”. To speak like Lalu you have to BE Lalu. (wow! that was a heavy one). On a serious note, being someone is different from acting someone, and thats where lies the success.

Till then, live the possibility of being a “PJayer“.

Tuesday, December 12, 2006

Delhi Barcamp-2

Past Saturday (9th Dec'06) was this year's second Barcamp in Delhi. Venue was Impetus Software building in Noida. Although, the space was a little less compared to Adobe. But, nevertheless it was pretty cozy and well-managed.
Unfortunately, I could attend only the first half of this unconferencing. All the topics were around web technologies, alteast the ones I attended. In all, it was a great experience, as all geeks gathered to share the podium. The energy level was great. Presentations are available thru slideshare at http://barcamp.org/BarCampDelhi-2

Wednesday, April 12, 2006

'm'-bridge My Country

Wow! it feels great to be part of this "ecosystem". I've been planning to start blogging for quite some time now, not that i didn't have a pc or time for it. Actually, it was the price tag attached with being on-line. Now, that broadband is becoming a lingo of commoners, I can certainly afford it. By-the-way @128kbps i'm still not in the elite category of broadband users,as, TRAI says anything above 256kbps is broadband in India. So, all you "firangees" update ur books for proper definition.
Pleasure of writing in the comfort of home reminds me of the time, not too long back, when I took British Library membership because it had free internet surfing for its members. Forget about surfing.......voice was a luxury. Alright!!! times have been consistently changing in telecom, specially in India. Did we get Chinese infection? Yeah....for good and the great news is that it has just started!!!
Remember those days of walkie-talkie sized mobiles and Rs. 20-30 outgoing MOU and half the price for incoming. Yeah and you wouldn't believe ....I saw few talking on that machine too!!!! Now, it takes Re 1 for call and they might start paying you for listening to them. What's causing this plunge in prices? Well, Rs 20 was annoyingly unreasonable, but, Re 1 !!!
It would be interesting to find out where my money goes when I pay my phone bill? It is essentially rental+ call usage+sms+data+vas (wap,news et. al). Now, it would be even more interesting to findout how much of this money is going down to the operator(s). I'm specifically interested in finding out what essentially is bringing the prices to lower levels. Having said that!! Here are the essential components which make the major chunk of telcos(Not sure if there are more though).
1. IUC (Interconnect Usage Charges) - thats what telcos share for using each other's resources.
2. ADC (Access Deficit Charge) - thats what every telco pays BSNL for pushing NLD calls to them.


The recent cut down on ADC substantially reduced the prices of call usage. ARPU has declined considerably for operators. Don't get surprised if you hear that Indians are enjoying the lowest mobile telephoney tariffs in the world. At the same time don't get surprised to hear that India is having one of the most prohibitive regulatory costs (like spectrum usage charges, license fee, ADC, service tax etc). Thats that then......

So, when carrier (essentially voice) prices are touching the ground, where do we expect the market economy to shift? Is it going to be services, data, content ?Well it looks quite complex to me at the moment.......At least internet prices have come down!!! I'm happy surfing reasonably fast web at reduced prices.Now that broadband is making its foray into Indian market, I guess its going to see a tremendeous competetion. Soon, broadband will become a household, soon, their will be competetion for broadband based services like (video-on-demand, IP TV maybe etc). I hope that this "soon" is really soon.

Whats the motivation for telecom software companies in India. I know for sure that most of the software developed in India is exported,but, isn't India the fastest growing telecom market in the world? It would be rather interesting to find out what kind of telecom softwares are booming in India (mobile gaming, content publishing, unified messaging,prepaid, et.al)

At the end lets not forget that we are still tottering at 11 - 11.5 teledensity. TRAI's projected figure for 2007 is 22.5 , quite impressive isn't it. So, in all, future looks quite green for us consumers.

May be i'll start video-blogging then :-)