You are currently browsing the FeradZ Blog blog archives for December, 2008


Problems with IBM Lenovo T60 Laptops

Since August 2006 I use IBM Lenovo T60 laptop. It is very stylish laptop. I have it dual boot Windows (had XP and now have Vista) and Linux (Ubuntu). It works perfectly with these operating systems. It is very easy to find drivers. I love the high resolution 1400×1050 on 14" screen and the overall performance delivered by 1.8GHz Dual Core and 4G Ram.

BUT

Since August 2006, because of technical problems I changed 2 laptops and this is my 3d one. Also my colleagues experienced similar problems and in our team 5 out of 12 member have changed their laptops at least once because of various problems – mainly cooling fan failure. In my particular case the problems were as follows:

  1. The battery of the laptop was taken off and my home mate accidentally unplugged the power cable. After that the computer didn’t turn on. I had to change it.
  2. The computer start overheating and rebooting. This damaged my file system and I spent 2 days trying to restore my lost files. The problem was problem with the fan.

Other main problem of these computers is the battery. We have 6 cell Li-On batteries. Their life is extremely short. I changed my first battery before about 3,5 months and it was completely death. I got my second battery provisional. When I got the second battery IBM’s Power Manager software was showing:

  • First used date: September 2006
  • Condition: Good
  • Store Capacity: 88%
  • Cycle count: 78
  • I was able to use the computer for 1,5-2 hours

Now after using the for 3,5 months the Power Manager software shows:

  • First used date: September 2006
  • Condition: Poor
  • Store Capacity: 44%
  • Cycle count: 110
  • I am able to use the computer for 30-45 minutes

So for 3,5 months the performance of the battery life dropped to more than two times. I am not battery expert but this is very bad performance for a battery. One of my colleagues also changed his battery and other is about to change so 30% of the people in the team. Unfortunately this post became a bit criticising but after seeing the notification for changing my battery because of its poor performance I decided to write about the negative sides of my personal experience using IBM Lenovo T60 laptop.

Windows: Time of Last Reboot and Time Since Last Boot

Today I needed to check the last time when one of our win servers was rebooted and the time it elapsed since its last boot.

So to check:

1. The time of last Reboot, go to Open Event Viewer (Control Panel, Administrative Tools). Look for the last Event Log 1074 with USER32 – this will contain information about the exact date and time of the last reboot.

2. The time since the last boot. A practical way I found is: open command prompt and type “net statistics server”. It will display summary info. The one that you should look for is the 2nd line “Statistics since…” this is the time since your computer is on.

Uninitialized Variable May Waste a Whole Day

Today I was writing a program and implement I implemented a method that parses contents of a raw byte buffer into different primitive data types – including 32bit address and store them in 64bit unsigned integers.

Because I had two class member fields with similar names and I missed to initialize one of them to 0. Then when I copy the 32bit address from the buffer into the 64bit integer variable, my program was crashing like crazy and I didn’t have a clue that it could be because of the uninitialized field. I was checking if the 64bit variable is equal to the expected value (like in the code demonstrated below) but haaahh, it was not equal. And again, no idea why?!? So inspecting the code carefully and inserting stupid printfs around (ok I was not able to debug my application with a debugger) I could found the nasty uninitialized field at the end of the day at 01:20 midnight.

So here comes the lesson: Uninitialized variables are very dangerous and besides wasting your time may cause irreversible problems. It looks I should be thankful that my libraries were crashing and not hiding the bug.
Below I attach the code segment that is an example of the error I had today.

To compile: g++ -g -o UninitializedFieldCpp UninitializedFieldCpp.cpp

//————————————————————————-
//
// How I wasted a whole day because of uninitialized member field in C++.
//
//————————————————————————-

//#include “stdafx.h”

#include
#include

using namespace std;

typedef unsigned long long ULONG64;
typedef unsigned int ULONG;
typedef unsigned char byte;

//
// Here we have 16 bytes
//
byte buffer[] = {0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00};

class MyClass
{
public:
MyClass():_initializedField(0) {}

void copyNumberUninitializedField()
{
//
// Here we get a pointer to the first FF byte in the buffer
//
byte* pointerToFF = buffer + 4;

memcpy(&_uninitializedField, pointerToFF, sizeof(ULONG));

if (_uninitializedField == 0xffffffff)
{
cout << “_uninitializedField: there is no problem” << endl;
}
else
{
cout << “ERROR: ” << endl;
cout << “_uninitializedField must be equal to 0xffffffff, but was: “;
cout << hex << _uninitializedField << endl;
}
}

void copyNumberInitializedField()
{
//
// Here we get a pointer to the first FF byte in the buffer
//
byte* pointerToFF = buffer + 4;

memcpy(&_initializedField, pointerToFF, sizeof(ULONG));

if (_initializedField == 0xffffffff)
{
cout << “_initializedField: there is no problem” << endl;
}
else
{
cout << “ERROR: ” << endl;
cout << “_initializedField must be equal to 0xffffffff, but was: “;
cout << hex << _initializedField << endl;
}
}

private:
//
// This is our uninitialized field.
//
ULONG64 _uninitializedField;

//
// This is our good initialized field
//
ULONG64 _initializedField;
};

int main(int argc, char* argv[])
{
MyClass m = MyClass();

m.copyNumberUninitializedField();

cout << endl << endl;

m.copyNumberInitializedField();

cout << “Done” << endl;

return 0;
}

Back from Istanbul

This post may be a bit late but I ardly had time to write it. Before 2 weeks I visited my friends and also relatives in Istanbul. For those who don’t know Istanbul is a cradle of cultures and well of history. My favorit places there that I like to spent my time are around Taksim, Ortakoy, 4. Levent, Sisli. This time I went to the workplace of a friend of mine who is resposnible in the construction of the highest skyskaper being built in Istanbul – Sapphire. We went to the top and I took photos with amazing views. It was really a full holiday.

Photo taken from the top of the highest skyskaper being built in Istanbul - Sapphire - 526m.

Photo taken from the top of the highest skyskaper being built in Istanbul - Sapphire - 526m.

Istiklal Street is the most famous street in Istanbul.

Istiklal Street is the most famous street in Istanbul.

WinDbg Extension – GetOffsetByName

In this post I would like to explain with a working example the sematics of the GetOffsetByName from IDebugSymbols interface in WinDbg Extension API.

  1. You can use this method to return the offset of a symbol that is in the data segment but not on the heap. Data segment is the place in the program where global variables are stored. If you try to get the offset of a field of a class instance (object) this will not work (e.g. instanceOfMyClass->fieldName).
  2. The value that this method returns as offset is address of the global variable i.e. &var. Lets explain with an example.

On the running example I assuming

class MyClass {

static int staticField.

};

myext.getoffsetbyname is the custom extension that implements GetOffsetByName

Then if we un the following commands in WinDbg command window

0:000:x86> x simple!MyClass::staticField

0x004d81e4 simple!MyClass::staticField = 0x00000005

0:000:x86> ?? &(MyClass::staticField)

class MyClass[] ** 0x004d81e4

0:000:x86> !tm.rset simple!MyClass::staticField

Symbol Offset: 0x004d81e4

0:000:x86> dd 0x004d81e4 L1

0x004d81e4 0x00000005


Address

Variable Name

Value

004d81e4 (&MyClass::staticField)

MyClass::staticField

0x00000005(value = 5)

And the file implementing the extension is given below. To build the code refer to Building DbgEng Extensions.

class EXT_CLASS : public ExtExtension {

public:

EXT_DECLARE_METHOD(getoffsetbyname);

};

EXT_DECLARE_GLOBALS();

EXT_COMMAND(getoffsetbyname,

“Prints the offset of a symbol.”,

“{;s,o,d=simple!MyData::staticField;symb;Symbol Name}”)

{

Out(“nReadset:n”);

HRESULT isOk = E_FAIL;

IDebugSymbols *symbols = this->m_Symbols;

PCSTR arg = GetUnnamedArgStr(0);

ULONG64 chunkOffset = 0;

isOk = symbols->GetOffsetByName(arg, &chunkOffset);

if (isOk == S_OK) {

Out(“Symbol Offset: %08x – %lun”, chunkOffset, chunkOffset);

}

else if (isOk == S_FALSE) {

Out(“Symbol Offset (many found): %08x – %lun”, chunkOffset, chunkOffset);

}

else {

Out(“Error: Symbol Offsetn”);

}

}

First Post

This is my first entry in the blog congratulating the beggining of a hopefully up to date blog.

Ferad Zyulkyarov