1. spencercw
  2. gb_emulator

Commits

spencercw  committed 6108ddd

#13 Partial implementation of displaying only variables that are in scope.

The CDB format does not provide enough information to be able to determine whether variables at a lower level than the current line are part of the current scope, so currently they are always displayed.

  • Participants
  • Parent commits 6537728
  • Branches default

Comments (0)

Files changed (6)

File gb_debugger_msvs/program.cpp

View file
 		end = gbStackFrames.rend(); frame != end; ++frame, ++i)
 	{
 		CComObject<CDocumentContext> *documentContext = NULL;
-		if ((*frame)->hasDebugInfo && (*frame)->sourceLocation.sourceFile)
+		if ((*frame)->hasDebugInfo && (*frame)->sourceLocation.line)
 		{
 			CComObject<CDocumentContext>::CreateInstance(&documentContext);
 			documentContext->AddRef();
-			documentContext->Init((*frame)->sourceLocation.sourceFile, (*frame)->sourceLocation.line);
+			documentContext->Init((*frame)->sourceLocation.line->file,
+				(*frame)->sourceLocation.line->line);
 		}
 
 		CComObject<CCodeContext> *codeContext;

File gb_debugger_msvs/properties/frame_property.cpp

View file
 	}
 
 	// Copy the variable data into an array of debug properties
-	size_t propertyCount = frame_->sourceLocation.function->locals.size();
-	scoped_array<CComPtr<CVariableProperty> > properties(
-		new CComPtr<CVariableProperty>[propertyCount]);
+	vector<CComPtr<CVariableProperty> > properties;
+	properties.reserve(frame_->sourceLocation.function->locals.size());
 
-	size_t i = 0;
 	for (vector<shared_ptr<CdbFile::Symbol> >::const_iterator
 		variable = frame_->sourceLocation.function->locals.begin(),
-		end = frame_->sourceLocation.function->locals.end(); variable != end; ++variable, ++i)
+		end = frame_->sourceLocation.function->locals.end(); variable != end; ++variable)
 	{
-		// Create the property
-		CComObject<CVariableProperty> *variableProperty;
-		CComObject<CVariableProperty>::CreateInstance(&variableProperty);
-		properties[i] = variableProperty;
-		variableProperty->Init(frame_, *variable);
+		// Create the property if the variable is in scope. Note this algorithm isn't quite
+		// accurate; any variables at a lower level to the current line will appear, even if they
+		// are not in scope. There is not enough information to be able to determine what blocks a
+		// block resides in.
+		if ((*variable)->block == frame_->sourceLocation.line->block ||
+			(*variable)->level < frame_->sourceLocation.line->level)
+		{
+			CComObject<CVariableProperty> *variableProperty;
+			CComObject<CVariableProperty>::CreateInstance(&variableProperty);
+			properties.push_back(variableProperty);
+			variableProperty->Init(frame_, *variable);
+		}
 	}
 
 	// Populate the property info structures
+	size_t propertyCount = properties.size();
 	scoped_array<DEBUG_PROPERTY_INFO> propertyInfo(new DEBUG_PROPERTY_INFO[propertyCount]);
-	for (size_t i = 0; i != propertyCount; ++i)
+	size_t i = 0;
+	for (vector<CComPtr<CVariableProperty> >::const_iterator prop = properties.begin(),
+		end = properties.end(); prop != end; ++prop, ++i)
 	{
-		properties[i]->PopulatePropertyInfo(&propertyInfo[i], fields, radix);
+		(*prop)->PopulatePropertyInfo(&propertyInfo[i], fields, radix);
 	}
 
 	// Create the enumerator

File gb_debugger_msvs/stack_frame.cpp

View file
 	static const GUID assemblyGuid =
 		{ 0x4bc19a8f, 0x8423, 0x4a8b, { 0x89, 0xcc, 0xee, 0x95, 0xfe, 0x9f, 0xbb, 0xb2 } };
 
-	if (!frame_->hasDebugInfo || !frame_->sourceLocation.sourceFile)
+	if (!frame_->hasDebugInfo || !frame_->sourceLocation.line)
 	{
 		return E_FAIL;
 	}
 
-	switch (frame_->sourceLocation.language)
+	switch (frame_->sourceLocation.line->language)
 	{
 	case CdbFile::ASSEMBLY:
 		*pbstrLanguage = SysAllocString(L"Assembly");
 		// Offset
 		if (fields & FIF_FUNCNAME_LINES && frame_->hasDebugInfo)
 		{
-			oss << dec << L"  Line " << frame_->sourceLocation.line + 1;
+			oss << dec << L"  Line " << frame_->sourceLocation.line->line + 1;
 			if (fields & FIF_FUNCNAME_OFFSET && frame_->sourceLocation.lineOffset)
 			{
 				if (frame_->sourceLocation.lineOffset > 0)
 		frameInfo->m_dwValidFields |= FIF_FUNCNAME;
 		frameInfo->m_bstrFuncName = SysAllocString(functionName.c_str());
 	}
-	if (fields & FIF_LANGUAGE && frame_->hasDebugInfo && frame_->sourceLocation.sourceFile)
+	if (fields & FIF_LANGUAGE && frame_->hasDebugInfo && frame_->sourceLocation.line)
 	{
 		frameInfo->m_dwValidFields |= FIF_LANGUAGE;
-		switch (frame_->sourceLocation.language)
+		switch (frame_->sourceLocation.line->language)
 		{
 		case CdbFile::ASSEMBLY:
 			frameInfo->m_bstrLanguage = SysAllocString(L"Assembly");

File gb_emulator/include/gb_emulator/cdb_file.h

View file
 		 */
 		unsigned line;
 		//! Source language.
-		Language languague;
+		Language language;
 		//! Start address of the line.
 		/**
 		 * The specification states that this is the end address of the line, but that does not
 		boost::shared_ptr<Symbol> function;
 		//! Offset from the beginning of the function in bytes.
 		int64_t functionOffset;
-		//! Source file.
+		//! The source line.
 		/**
 		 * This will be unset if no source information is available.
 		 */
-		boost::shared_ptr<File> sourceFile;
-		//! The language of the source file.
-		/**
-		 * If \c sourceFile is empty this value is unused.
-		 */
-		Language language;
-		//! Line number in the source file.
-		/**
-		 * If \c sourceFile is empty this value is unused.
-		 */
-		unsigned line;
+		boost::shared_ptr<Line> line;
 		//! Offset from the beginning of the line in bytes.
 		/**
-		 * If \c sourceFile is empty this value is unused.
+		 * If \c line is unset this value is unused.
 		 */
 		int64_t lineOffset;
 	};

File gb_emulator/src/cdb_file.cpp

View file
 		shared_ptr<Symbol> function = findFunction(line->second->address);
 
 		// Save the line
-		switch (line->second->languague)
+		switch (line->second->language)
 		{
 		case C:
 			if (!function)
 
 	if (isCLine)
 	{
-		lineData->languague = C;
+		lineData->language = C;
 		lineData->level = lexical_cast<unsigned>(results[3]);
 		lineData->block = lexical_cast<unsigned>(results[4]);
 
 	}
 	else
 	{
-		lineData->languague = ASSEMBLY;
+		lineData->language = ASSEMBLY;
 		lineData->level = 0;
 		lineData->block = 0;
 
 		sourceLocation.functionOffset = address - function->address;
 		if (cLine != function->cLines.end())
 		{
-			sourceLocation.sourceFile = cLine->second->file;
-			sourceLocation.language = C;
-			sourceLocation.line = cLine->second->line;
+			sourceLocation.line = cLine->second;
 			sourceLocation.lineOffset = address - cLine->second->address;
 		}
 		else if (asmLine != function->asmLines.end())
 		{
-			sourceLocation.sourceFile = asmLine->second->file;
-			sourceLocation.language = ASSEMBLY;
-			sourceLocation.line = asmLine->second->line;
+			sourceLocation.line = asmLine->second;
 			sourceLocation.lineOffset = 0;
 		}
 		else
 		{
-			sourceLocation.sourceFile.reset();
-			sourceLocation.language = ASSEMBLY;
-			sourceLocation.line = 0;
+			sourceLocation.line.reset();
 			sourceLocation.lineOffset = 0;
 		}
 
 		// Populate the output data
 		sourceLocation.function.reset();
 		sourceLocation.functionOffset = 0;
-		sourceLocation.sourceFile = line->second->file;
-		sourceLocation.language = ASSEMBLY;
-		sourceLocation.line = line->second->line;
+		sourceLocation.line = line->second;
 		sourceLocation.lineOffset = 0;
 
 		return true;

File gb_emulator/src/gb_debugger.cpp

View file
 			(*frame)->hasDebugInfo = false;
 			(*frame)->sourceLocation.function.reset();
 			(*frame)->sourceLocation.functionOffset = 0;
-			(*frame)->sourceLocation.sourceFile.reset();
-			(*frame)->sourceLocation.language = CdbFile::ASSEMBLY;
-			(*frame)->sourceLocation.line = 0;
+			(*frame)->sourceLocation.line.reset();
 			(*frame)->sourceLocation.lineOffset = 0;
 		}
 	}