blob: f5a4e8f5ab8ecab0335bf4bd5fda3ad942a480e2 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2011 Nokia and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Nokia - Initial API and implementation
*******************************************************************************/
#ifndef BREAKPOINTSERVICE_H_
#define BREAKPOINTSERVICE_H_
#include <map>
#include <string>
#include <vector>
#include "TCFService.h"
#include "TCFContext.h"
class WinProcess;
struct Channel;
struct Protocol;
enum TCFBreakpointType {
type_Auto,
type_Software,
type_Hardware
};
enum TCFAccessMode {
ACCESSMODE_READ = 0x01,
ACCESSMODE_WRITE = 0x02,
ACCESSMODE_EXECUTE = 0x04,
ACCESSMODE_CHANGE = 0x08,
};
typedef short AgentBreakID; // 32768 ought to be enough watchpoints
#define AGENT_BREAK_UNSET (-1)
//
// To store the breakpoint info
//
struct TBreakpoint {
std::vector<std::string> iContextIds;
WinProcess* process; // pointer to the process hosint the bkpt
std::string hostBreakPointId; // breakpoint ID from host debugger.
ContextAddress address;
bool enabled;
unsigned char originalByte; // original byte where we set the bp.
unsigned char size; // for windows-x86, max is well below 255
TCFBreakpointType requestedType;
TCFBreakpointType actualType;
TCFAccessMode accessMode; // _EXECUTE means bkpt; o/w -> watchpoint
AgentBreakID agentBreakID;
TBreakpoint()
: process(NULL), address(0), enabled(true), originalByte(0),
size(0), requestedType(type_Auto), actualType(type_Auto),
accessMode(ACCESSMODE_READ), agentBreakID(AGENT_BREAK_UNSET)
{}
bool SameProcess(const HANDLE& procH) const;
inline bool IsTypeBreakpoint() const
{ return ACCESSMODE_EXECUTE == accessMode; }
inline bool IsTypeWatchpoint() const
{ return ACCESSMODE_EXECUTE != accessMode; }
};
typedef std::map<std::string, TBreakpoint*> TID2BreakpointMap;
/*
* A list of breakpoints in all processes in the debug session.
*/
static TID2BreakpointMap sBreakPointMap;
//
// Breakpoint service implementation
//
class BreakpointsService: public TCFService {
public:
BreakpointsService(Protocol * proto);
const char* GetName();
static void CommandAddBreakpoint(const char* token, Channel*);
static void CommandRemoveBreakpoint(const char* token, Channel*);
static int InsertBreak(const TBreakpoint*);
static int ClearBreak(const TBreakpoint*);
static int InsertWatch(TBreakpoint*);
static int ClearWatch(TBreakpoint*);
static int RemoveProcessFromBreakpoints(const WinProcess*);
static TBreakpoint* FindBreakpointByAddress(const HANDLE& processHandle,
const ContextAddress);
static TBreakpoint* FindWatchpointByAddress(const HANDLE& processHandle,
const ContextAddress);
static void RemoveBreakpointsFromMemoryRead(const HANDLE& processHandle,
const ContextAddress, char* memBuffer, const unsigned long size);
static void ReInsertBreakpointsAfterMemoryWrite(
const HANDLE& processHandle, const ContextAddress, char* memBuffer,
const unsigned long size);
static bool ServiceInstalled();
private:
static bool sServiceInstalled;
};
#endif /* BREAKPOINTSERVICE_H_ */