void stacktrace(){
	unsigned long framePointer;
	unsigned long savedEIP;
	unsigned long lowPC;
	unsigned long highPC;
	int functionFound = 0;
	int functionCount = 0;
	char * functionName;
	char * fileName;
	Dwarf_Die functionDie;

	// Find our current Function
	functionDie = dwarf_get_next_function(compilation_unit->root_die,compilation_unit);
	savedEIP = findAddress(CURRENT_EIP);
	while(!functionFound){
		lowPC = dwarf_function_starting_address(functionDie,compilation_unit);
		highPC = dwarf_function_ending_address(functionDie,compilation_unit);
		if((savedEIP >= lowPC) && (savedEIP < highPC)){
			fileName = dwarf_get_name(compilation_unit->root_die,compilation_unit);
			functionName = dwarf_get_name(functionDie,compilation_unit);
			printf("#%d %s(",functionCount,functionName);
			printPassedVariable(functionDie);
			printf(") at %s:%d\n",fileName,findLineNumber(savedEIP));
			functionFound = 1;
			++functionCount;
		}
		else
			functionDie = dwarf_get_next_function(functionDie,compilation_unit);
	}
	functionFound = 0;

	framePointer = findAddress(FRAME_POINTER);
	while(ptrace(PTRACE_PEEKTEXT,child,framePointer,NULL) != 0){
		savedEIP = ptrace(PTRACE_PEEKTEXT,child,framePointer+4,NULL);	// Give us our old EBP
		framePointer = ptrace(PTRACE_PEEKTEXT,child,framePointer,NULL);

		// Now look for function DIE
		functionDie = dwarf_get_next_function(compilation_unit->root_die,compilation_unit);
		while(!functionFound){
			lowPC = dwarf_function_starting_address(functionDie,compilation_unit);
			highPC = dwarf_function_ending_address(functionDie,compilation_unit);
			if((savedEIP >= lowPC) && (savedEIP < highPC)){
				fileName = dwarf_get_name(compilation_unit->root_die,compilation_unit);
				functionName = dwarf_get_name(functionDie,compilation_unit);
				printf("#%d %s() at %s:%d\n",functionCount,functionName,fileName,findLineNumber(savedEIP));
				functionFound = 1;
			}
			else
				functionDie = dwarf_get_next_function(functionDie,compilation_unit);
		}
		functionFound = 0;
	}
}
int Doc_Test::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: initTestCase(); break;
        case 1: defaults(); break;
        case 2: addFixture(); break;
        case 3: deleteFixture(); break;
        case 4: fixtureLimits(); break;
        case 5: fixture(); break;
        case 6: findAddress(); break;
        case 7: totalPowerConsumption(); break;
        case 8: addFunction(); break;
        case 9: deleteFunction(); break;
        case 10: function(); break;
        case 11: functionLimits(); break;
        case 12: load(); break;
        case 13: loadWrongRoot(); break;
        case 14: save(); break;
        default: ;
        }
        _id -= 15;
    }
    return _id;
}
// Takes address from EIP register and checks it against our breakpoints array
// Returns index/breakpoint number
int findBreakpoint(int code){
	unsigned long currentAddress = findAddress(code);

	int i = 0;
	while(currentAddress != breakpoints[i][0]){ ++i;}
	return i;
}
Exemple #4
0
void AddFixture::findAddress()
{
    /* Find the next free address space for x fixtures, each taking y
       channels, leaving z channels gap in-between. */
    quint32 address = findAddress((m_channelsValue + m_gapValue) * m_amountValue,
                                  m_doc->fixtures(),
                                  m_doc->inputOutputMap()->universesCount());

    /* Set the address only if the channel space was really found */
    if (address != QLCChannel::invalid())
    {
        m_universeCombo->setCurrentIndex(address >> 9);
        m_addressSpin->setValue((address & 0x01FF) + 1);
    }
int AddFixture_Test::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: initTestCase(); break;
        case 1: findAddress(); break;
        case 2: initialNoFixture(); break;
        case 3: initialDimmer(); break;
        case 4: initialScanner(); break;
        case 5: selectionNothing(); break;
        case 6: selectionGeneric(); break;
        default: ;
        }
        _id -= 7;
    }
    return _id;
}
Exemple #6
0
AddFixture::AddFixture(QWidget* parent, const Doc* doc, const Fixture* fxi)
    : QDialog(parent)
    , m_doc(doc)
{
    m_addressValue = 0;
    m_universeValue = 0;
    m_amountValue = 1;
    m_gapValue = 0;
    m_channelsValue = 1;
    m_fixtureDef = NULL;
    m_mode = NULL;
    m_fxiCount = 0;
    m_fixtureID = Fixture::invalidId();
    m_invalidAddressFlag = false;

    setupUi(this);
    m_addrErrorLabel->hide();

    QAction* action = new QAction(this);
    action->setShortcut(QKeySequence(QKeySequence::Close));
    connect(action, SIGNAL(triggered(bool)), this, SLOT(reject()));
    addAction(action);

    connect(m_tree, SIGNAL(itemSelectionChanged()),
            this, SLOT(slotSelectionChanged()));
    connect(m_tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),
            this, SLOT(slotTreeDoubleClicked(QTreeWidgetItem*)));
    connect(m_modeCombo, SIGNAL(activated(const QString&)),
            this, SLOT(slotModeActivated(const QString&)));
    connect(m_universeCombo, SIGNAL(activated(int)),
            this, SLOT(slotUniverseActivated(int)));
    connect(m_addressSpin, SIGNAL(valueChanged(int)),
            this, SLOT(slotAddressChanged(int)));
    connect(m_channelsSpin, SIGNAL(valueChanged(int)),
            this, SLOT(slotChannelsChanged(int)));
    connect(m_nameEdit, SIGNAL(textEdited(const QString&)),
            this, SLOT(slotNameEdited(const QString&)));
    connect(m_gapSpin, SIGNAL(valueChanged(int)),
            this, SLOT(slotGapSpinChanged(int)));
    connect(m_amountSpin, SIGNAL(valueChanged(int)),
            this, SLOT(slotAmountSpinChanged(int)));
    connect(m_searchEdit, SIGNAL(textChanged(QString)),
            this, SLOT(slotSearchFilterChanged(QString)));
    connect(m_diptoolButton, SIGNAL(clicked()),
            this, SLOT(slotDiptoolButtonClicked()));

    /* Fill fixture definition tree (and select a fixture def) */
    if (fxi != NULL)
    {
        fillTree(fxi->fixtureDef()->manufacturer(), fxi->fixtureDef()->model());
        m_fixtureID = fxi->id();
    }
    else
        fillTree(KXMLFixtureGeneric, KXMLFixtureGeneric);

    m_fixturesCount->setText(tr("Fixtures found: %1").arg(m_fxiCount));

    /* Fill universe combo with available universes */
    m_universeCombo->addItems(m_doc->inputOutputMap()->universeNames());

    /* Simulate first selection and find the next free address */
    slotSelectionChanged();

    if (fxi != NULL)
    {
        // Universe
        m_universeCombo->setCurrentIndex(fxi->universe());
        slotUniverseActivated(fxi->universe());

        m_addressSpin->setValue(fxi->address() + 1);
        m_addressValue = fxi->address();

        m_multipleGroup->setEnabled(false);

        // Name
        m_nameEdit->setText(fxi->name());
        slotNameEdited(fxi->name());
        m_nameEdit->setModified(true); // Prevent auto-naming

        // Mode
        int index = m_modeCombo->findText(fxi->fixtureMode()->name());
        if (index != -1)
        {
            m_channelsSpin->setValue(fxi->channels());
            m_modeCombo->setCurrentIndex(index);
            slotModeActivated(m_modeCombo->itemText(index));
        }
    }
    else
    {
        slotUniverseActivated(0);
        findAddress();

        m_channelsSpin->setValue(1);
    }

    QSettings settings;
    QVariant var = settings.value(SETTINGS_GEOMETRY);
    if (var.isValid() == true)
        restoreGeometry(var.toByteArray());
    AppUtil::ensureWidgetIsVisible(this);
}
Exemple #7
0
AddFixture::AddFixture(QWidget* parent,
		       const QLCFixtureDefCache& fixtureDefCache,
		       const Doc& doc,
		       const OutputMap& outputMap,
		       const QString& selectManufacturer,
		       const QString& selectModel,
		       const QString& selectMode,
		       const QString& selectName,
		       int selectUniverse,
		       int selectAddress,
		       int selectChannels)
	: QDialog(parent),
	m_fixtureDefCache(fixtureDefCache),
	m_doc(doc),
	m_outputMap(outputMap)
{
	m_addressValue = 0;
	m_universeValue = 0;
	m_amountValue = 1;
	m_gapValue = 0;
	m_channelsValue = 1;
	m_fixtureDef = NULL;
	m_mode = NULL;

	setupUi(this);

	m_tree->header()->setResizeMode(QHeaderView::ResizeToContents);

	connect(m_tree, SIGNAL(itemSelectionChanged()),
		this, SLOT(slotSelectionChanged()));
	connect(m_tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),
		this, SLOT(slotTreeDoubleClicked(QTreeWidgetItem*)));
	connect(m_modeCombo, SIGNAL(activated(const QString&)),
		this, SLOT(slotModeActivated(const QString&)));
	connect(m_universeCombo, SIGNAL(activated(int)),
		this, SLOT(slotUniverseActivated(int)));
	connect(m_addressSpin, SIGNAL(valueChanged(int)),
		this, SLOT(slotAddressChanged(int)));
	connect(m_channelsSpin, SIGNAL(valueChanged(int)),
		this, SLOT(slotChannelsChanged(int)));
	connect(m_nameEdit, SIGNAL(textEdited(const QString&)),
		this, SLOT(slotNameEdited(const QString&)));
	connect(m_gapSpin, SIGNAL(valueChanged(int)),
		this, SLOT(slotGapSpinChanged(int)));
	connect(m_amountSpin, SIGNAL(valueChanged(int)),
		this, SLOT(slotAmountSpinChanged(int)));

	/* Fill fixture definition tree */
	fillTree(selectManufacturer, selectModel);

	/* Fill universe combo with available universes */
	m_universeCombo->addItems(m_outputMap.universeNames());

	/* Simulate first selection and find the next free address */
	slotSelectionChanged();

	if (selectAddress == -1 && selectUniverse == -1)
	{
		slotUniverseActivated(0);
		findAddress();
	}
	else
	{
		m_universeCombo->setCurrentIndex(selectUniverse);
		slotUniverseActivated(selectUniverse);

		if (m_outputMap.isDMXZeroBased(m_universeValue) == true)
			m_addressSpin->setValue(selectAddress);
		else
			m_addressSpin->setValue(selectAddress + 1);
		m_addressValue = selectAddress;

		m_multipleGroup->setEnabled(false);
	}

	if (selectName.isEmpty() == false)
	{
		m_nameEdit->setText(selectName);
		slotNameEdited(selectName);
	}

	if (selectMode.isEmpty() == false)
	{
		int index = m_modeCombo->findText(selectMode);
		if (index != -1)
		{
			m_modeCombo->setCurrentIndex(index);
			slotModeActivated(m_modeCombo->itemText(index));
		}
	}
	else
	{
		m_channelsSpin->setValue(selectChannels);
	}

	QSettings settings;
	QVariant var = settings.value(SETTINGS_GEOMETRY);
	if (var.isValid() == true)
		restoreGeometry(var.toByteArray());
}
// This one is a doosey. We are given a format and a variable name, and
// our job is to find it and print it out! There's loads to this one, better
// to just go through the function and read the step-by-step comments.
void printVariable(char * format, char * var, int generic){
	Dwarf_Die functionDie;	// DIE for our function
	Dwarf_Die variableDie;	// DIE for our variable
	Dwarf_Die previousDie;	// DIE for the previous variable
	Dwarf_Loc variableLocation;	// Location of our DIE
	int variableFound;
	unsigned long lowPC;
	unsigned long highPC;
	unsigned long currentAddress;
	unsigned long variableAddr;
	int locationType;
	int variableOffset;
	int variableData;

	struct user_regs_struct regs;
	ptrace(PTRACE_GETREGS,child,NULL,&regs);

	currentAddress = findAddress(AT_BREAKPOINT);

	variableFound = 0;
	previousDie = NULL;

	// First, check our globals!
	variableDie = dwarf_get_next_variable(compilation_unit->root_die,compilation_unit);
	while((variableDie != NULL) && (variableFound == 0)){
		if(strcmp(var,dwarf_get_name(variableDie,compilation_unit)) == 0){
			variableLocation = dwarf_get_variable_location(variableDie,compilation_unit);
			variableAddr = dwarf_get_variable_loc_addr(variableLocation);
			if(variableAddr != 0)
				variableFound = 1;
			else
				variableDie = dwarf_get_next_variable(variableDie,compilation_unit);
		}
		else
			variableDie = dwarf_get_next_variable(variableDie,compilation_unit);
	}

	// If it isn't a gloabl, check variables within our functions!
	functionDie = dwarf_get_next_function(compilation_unit->root_die,compilation_unit);	// Get the first function
	// Is our instructions address within the starting and ending range?
	while(functionDie != NULL && variableFound == 0){
		lowPC = dwarf_function_starting_address(functionDie,compilation_unit);
		highPC = dwarf_function_ending_address(functionDie,compilation_unit);
		if((currentAddress >= lowPC) && (currentAddress < highPC)){
			variableDie = dwarf_get_next_variable(functionDie,compilation_unit);
			while((variableDie != NULL) && variableFound == 0){
				if(strcmp(var,dwarf_get_name(variableDie,compilation_unit)) == 0){
					// We found our variable! Now we need to print out the correct statement
					// To do that, we need to find the value for our variable, and to do THAT
					// we need to find its location. As of right now I'm not sure that we will
					// ever have a location type of 3. This is checking for scope of just the function,
					// but then again I don't know!
					variableLocation = dwarf_get_variable_location(variableDie,compilation_unit);
					locationType = dwarf_get_variable_loc_type(variableLocation);
					variableAddr;
					if((locationType == 1) || (locationType == 2)){
						variableOffset = dwarf_get_variable_loc_offset(variableLocation);
						// Location type is SP OFFSET
						if(locationType == 1)
							variableAddr = variableOffset + regs.esp;
						// Location type is BP OFFSET
						if(locationType == 2)
							variableAddr = variableOffset + regs.ebp + 0x8;
					}
					if(locationType == 3){
						variableAddr = dwarf_get_variable_loc_addr(variableLocation);
					}

					variableFound = 1;
				}
				else
					variableDie = dwarf_get_next_variable(variableDie,compilation_unit);
			}
		}
		else
			functionDie = dwarf_get_next_function(functionDie,compilation_unit);
	}
	if(variableFound && !generic){
		variableData = ptrace(PTRACE_PEEKTEXT,child,variableAddr,NULL);
		if(strcmp(format, "/c") == 0)
			printf("%c\n",(char)variableData);
		if(strcmp(format,"/d") == 0)
			printf("%d\n",variableData);
		if(strcmp(format,"/s") == 0){
			char variableChar;
			printf("\"");
			while(variableChar){
				variableChar = (char)ptrace(PTRACE_PEEKTEXT,child,variableData,NULL);
				printf("%c",variableChar);
				++variableData;
			}
			printf("\"");
			printf("\n");
		}
	}
	if(variableFound && generic){
		variableData = ptrace(PTRACE_PEEKTEXT,child,variableAddr,NULL);
		int dataType = dwarf_get_data_type(variableDie,compilation_unit);
		if(dataType == DW_ATE_signed_char)
			printf("%c\n",(char)variableData);
		if(dataType == DW_ATE_signed)
			printf("%d\n",variableData);
		if(dataType == (DW_ATE_signed_char + 100)){
			char variableChar;
			printf("\"");
			while(variableChar){
				variableChar = (char)ptrace(PTRACE_PEEKTEXT,child,variableData,NULL);
				printf("%c",variableChar);
				++variableData;
			}
			printf("\"");
			printf("\n");
		}
	}
	if(!variableFound)
		printf("Variable '%s' not within scope!\n",var);
}