This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
class B; | |
class A | |
{ | |
public: | |
A() : x(0) {} | |
A(const B& b) { printf("copy constructor A is called\n"); } | |
void set_x(int x) { this->x = x * 10; } | |
int x; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gdb | |
def read_source_code(filename, target_line, num_lines): | |
with open(filename, 'r') as fr: | |
target_line -= 1 | |
lines = [' | ' + line[:-1] for line in fr] | |
lines[target_line] = '->| ' + lines[target_line][4:] | |
offset = num_lines / 2 | |
return lines[target_line - offset : target_line + offset] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#ifdef DEBUG_PRINT | |
#define DebugPrintf(format, args...) fprintf(stderr, "%s this=%p " format, __PRETTY_FUNCTION__, this, ##args) | |
#else | |
#define DebugPrintf(format, args...) | |
#endif | |
class Calculator | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gdb | |
class ShorternBacktraceCommand(gdb.Command): | |
'''Show a backtrace without argument info in each frame.''' | |
def __init__(self): | |
super(ShorternBacktraceCommand, self).__init__ ("bt", | |
gdb.COMMAND_SUPPORT, | |
gdb.COMPLETE_NONE) | |
def invoke(self, arg, from_tty): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gdb | |
import re | |
class ShorternBacktraceCommand(gdb.Command): | |
'''Show a backtrace without argument info in each frame.''' | |
def __init__(self): | |
super(ShorternBacktraceCommand, self).__init__ ("bt", | |
gdb.COMMAND_SUPPORT, | |
gdb.COMPLETE_NONE) | |
def invoke(self, arg, from_tty): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Ref. http://sourceware.org/gdb/onlinedocs/gdb/Index-Files.html | |
if [ $# -ne 1 ]; then | |
echo -e "$0 <binary>\n" | |
echo -e "Add gdb index to <binary>\n" | |
exit 1 | |
fi | |
binary="$1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ref. chromium/src/base/debug/debugger_posix.cc | |
#include <errno.h> | |
#include <fcntl.h> | |
#include <string.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <unistd.h> | |
#include <iostream> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
OUT="/tmp/htop.out" | |
/bin/bash -c "sleep 1; killall htop" & | |
htop > $OUT | |
# Ref. Remove color codes (special characters) with sed | |
# http://www.commandlinefu.com/commands/view/3584/remove-color-codes-special-characters-with-sed | |
result=$(sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" $OUT | sed 's/.*Mem.*[^0-9]\([0-9]\+\/[0-9]\+\)MB.*Swp.*/\1\n/') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(void) { | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat Outer.java | |
class Outer { | |
class Inner { | |
void foo() { | |
System.out.println(Outer.this.x); | |
} | |
} | |
private int x = 3; | |
public static void main(String[] args) { | |
Outer outer = new Outer(); |