Tuesday, May 21, 2013

Passing arguments to program when using GDB command line

If you have a program that takes input parameters on start and you want to debug it using GDB in the command line, here is how to pass parameters to the program:
  1. Start GDB with given program
    gdb myProgram.a
  2. Set break points etc. 
  3.  Start debugging and give parameters you would usually give to program here
    run param1 param2 
Alternatively you can specify arguments directly when calling gdb with --args flag:
gdb --args myProgram.a param1 param2

Cheatsheet for GDB command line: http://www.yolinux.com/TUTORIALS/GDB-Commands.html

Source: http://bytes.com/topic/c/answers/833755-how-do-i-pass-argument-gdb

Wednesday, May 15, 2013

Remote Desktop Windows To Linux

There are probably a ton of ways to do this, but here is one.:)
Use X11VNC on Linux and a standalone TightVNC client to connect to the Linux machine from Windows.
  1.  Install X11VNC on Linux (Ubuntu)
    sudo apt-get install x11vnc
  2. Run the VNC server on Linux
    x11vnc
    or
    x11vnc -forever
    to keep listening for new connections after the first client has disconnected.
    WARNING: X11VNC runs without password as default, you should set a password if you intend to let the server run in the background or for longer periods.
  3. Download standalone (or installer if you have the rights to install) of TightVNC:
    Latest version, installer only:
    http://www.tightvnc.com/download.php
    Old version, standalone:
    http://www.tightvnc.com/download-old.php
    http://www.tightvnc.com/download/1.3.10/tightvnc-1.3.10_x86_viewer.zip
  4. Connect to your Linux machine (use ifconfig to get IP-address) using the TightVNC viewer.
Consider adding x11vnc-forever to your /etc/rc.local and make it executable to start a VNC server when your computer boots.

Wednesday, May 8, 2013

Google Test check for derived class pointer

I have a function that creates an object of a derived/child Derived class and passes this object as a pointer to a function accepting a pointer of the base/parent Base class.

Now I wanted to test this using the Google Test Framework in conjunction with Google Mock:

TEST_F(myClassToBeTestedTest, functionToBeTestedTest)
{
    EXPECT_CALL(myClassMock, myFunc(::testing::A<Derived *>()));
    myClassToBeTested.functionToBeTested();
}


This did not compile with the following error:

mytestclasstest.cpp:X:Y: error: no matching function for call to 'MyClassMock::gmock_myFunc(testing::Matcher<Derived*>)'
mytestclasstest.cpp:X:Y: note: candidate is:
myclassmock.h:X:Y: note: testing::internal::MockSpec<void(Base*)>& 'MyClassMock::gmock_myFunc(const testing::Matcher<Base*>&)

...

Googling a bit I found http://stackoverflow.com/questions/5056538/google-mock-using-testingan which explained that Google Test needed const and &. However I couldn't get this to make sense for my type argument. E.g. EXPECT_CALL(myClassMock, myFunc(const ::testing::A<Derived *>() &)); doesn't work.

After more searching (and annoyance at google for removing :: and <>) I ended up with creating my own custom matcher using "Using Predicates as Matchers" from http://code.google.com/p/googlemock/wiki/CookBook#Using_Predicates_as_Matchers together with http://stackoverflow.com/questions/500493/c-equivalent-of-instanceof to check if object is type of Derived:

int IsDerived(Base * base)
{
    Derived * derived = dynamic_cast<Derived *>(base);
    return derived != NULL ? 1 : 0;
}

TEST_F(myClassToBeTestedTest, functionToBeTestedTest)
{
    EXPECT_CALL(myClassMock, myFunc(::testing::Truly(IsDerived)));
    myClassToBeTested.functionToBeTested();
}

Wednesday, April 10, 2013

HTC Titan Wp 7.5 Disables cellular data after screensaver

My HTC Titan suddenly startet turning off my cellular data (3G) after I turned off the screen for a little while (immediately turning the screen back on and it would still be enabled so it seems to be some kind of timeout).

Workaround for this problem:
1. Turn the phone off and then on again.
OR
2. Go to settings -> Flight Mode -> Turn flight mode on -> Turn flight mode off -> enter PIN code (if asked).

Will add solution to problem if I can find any.

Thursday, February 28, 2013

Termios to get Ncurses cbreak without Ncurses

In my C++ program I wanted to capture keypresses in command line without waiting for newline/enter being entered.
Ncurses has a command cbreak() which does this, but I wasn't using Ncurses.

I finally found termios.h library and tcgetattr()/tcsetattr() commands:


#include <termios.h>

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

{
    struct termios m_old_term_config;
    struct termios m_new_term_config;

    // Get current terminal configuration
    tcgetattr(STDIN_FILENO, &m_old_term_config);

    // Make a copy to restore later
    m_new_term_config = m_old_term_config;

    // Disable line by line input and echo
    m_new_term_config.c_lflag &= ~(ICANON | ECHO);

    // Or only disable line by line input
    //m_new_term_config.c_lflag &= ~ICANON

    tcsetattr(STDIN_FILENO, TCSANOW, &m_new_term_config);

    /* Run program without line by line input and echoing  */

    // Restore old terminal configuration when closing program
    tcsetattr(STDIN_FILENO, TCSANOW, &m_old_term_config);
}



Sources: http://linux.die.net/man/3/termios
http://en.wikibooks.org/wiki/Serial_Programming/termios

Saturday, December 15, 2012

Jailbreaking Windows Phone 7.5 HTC Titan

I have a HTC Titan (X310e) which suddenly turned into garbage when it would only show a garbled home screen after having the screen turned off once (Everything looked fine after reboot). Also all my email "apps" were missing and I could not access anything social (People, or settings about People og social networks).

After lots of Googling, I gave up on finding a solution online. I decided to delete everything on the phone and jailbreak it (since vanilla WP7 didn't have any backup functions anyways).

I followed this tutorial: forum.xda-developers.com/showpost.php?p=26842868&postcount=46
So thanks to dragonide from XDA Developers.

The tutorial was good, but I'll add some minor details that might be useful:
  • Download files from:
    DFT__HSPL_WP7SG1.rar: http://htcfanboys.com/download/cotulla/?action=view&file=10777
    DFT Eternity 24 langs Freedom V1 Pearl Edition.7z: http://forum.xda-developers.com/showthread.php?t=1684907
    RUU_ETERNITY_Radio_Signed_17.5006.08.27_17.08.50.06.7z: http://www.mediafire.com/download.php?6i5r5a5amkwx8h
  • Turn off your phone and disconnect it from the computer.
  • Remove your SIM card.
  • Hold volume up and down then press power. continue holding the volume buttons.
  • When you see green text on white background with for example version PI39100
    Radio 17.0...
    ..., you are in SPL. It should also say "Serial" about 2/3 of the way down the screen
  •  Connect to computer with USB. you might have to try different USB ports. Check"Safely Remove Hardware and Eject Media" in the system tray; My phone came up as Titan USB Sync on some ports, in that case flashing failed with 264 and 266 errors. (See http://forum.xda-developers.com/wiki/index.php?title=Elf_RUU_Error_Codes for explanation of errors). When it came up as Qualcomm CDMA Technologies MSM on a port, flashing worked fine.
  • Unpack DFT__HSPL_WP7SG1.rar using for example 7-Zip (http://www.7-zip.org/), just right click the file and select open archive.
  • Run \DFT_HSPL_WP7SG1\1_SPL205\TITAN\ROMUpdateUtility.exe and follow instructions (takes about 1 min).
  •  You should see the progress bar in parallel on both the computer and the phone.
  • When complete, the phone reboots. Hold the volume buttons until you enter SPL. Notice that it now says "HSPL2.5.160015.3 (137079)" and "Radio-16.23.06.10" (Radio was 17... before flashing on my phone).
  • Run \DFT_HSPL_WP7SG1\2_HSPL\DFT_HSPL_WP7SG1_INSTALL.exe and follow instructions (install HSPL) (takes about 1 min).
  • Phone will reboot after flashing. When rebooting, hold volume to enter SPL.
  •  Unpack DFT Eternity 24 langs Freedom V1 Pearl Edition.7z.
  •  Run \DFT Eternity 24 langs Freedom V1 Pearl Edition\ROMUpdateUtility.exe and follow instructions (takes about 10 min).
  • After completing flashing the phone will reboot and probably hang/freeze on boot (just showing the HTC logo). Reboot phone (just hold the power button or remove the battery). Hold volume buttons to enter SPL.
  • Unpack RUU_ETERNITY_Radio_Signed_17.5006.08.27_17.08.50.06.7z
  • Run \RUU_ETERNITY_Radio_Signed_17.5006.08.27_17.08.50.06\ROMUpdateUtility.exe (takes less than 1 minute).
  • After flashing, the phone reboots, hold volume buttons to enter SPL and check that Radio is now 17.5006.08.27
  • Turn off the phone (remove the battery).
  • Put your SIM card back in.
  • Power on the phone like normal and go through the Windows Phone 7 setup process.
  • Enjoy jailbroken WP7.
Note: My system is a Windows 7 machine, things may differ on your system.

Images of what you should expect to see (sorry for the blur):











Thanks to Sources:
http://windowsphone.stackexchange.com/questions/173/what-are-the-options-for-developer-unlocking-a-wp7-device
http://windowsphonehacker.com/articles/hspl_and_first_custom_roms_out_for_htc_titan_radar-06-01-12
http://forum.xda-developers.com/showthread.php?t=1684912
http://forum.xda-developers.com/showthread.php?t=1684907
http://forum.xda-developers.com/showthread.php?t=1684912&page=11
http://forum.xda-developers.com/showpost.php?p=26842868&postcount=46
http://forum.xda-developers.com/wiki/index.php?title=Elf_RUU_Error_Codes
http://forum.xda-developers.com/wiki/ActiveSync

Thursday, November 15, 2012