Problem with setting flag in Debug register

Hi ,I have a question, why this sample code fails with an Attribute Error:
specifically with : “AttributeError: ‘bool’ object has no attribute ‘Dr6’”

the code itself is :

if self.context.Dr6 & 0x1 and self.hardware_breakpoints.has_key(0):

This means that self.context is a boolean variable (so, equal to True or False). You can check that by adding a print statement,

print("self.context = ", self.context)

just above your if statement.

thank you for answering, but context.Dr6 is supposed to be a register ,just like in accessing the CONTEXT Struct in Windows C++.
How could I make it work ,accessing the correct value in the register ?

the python struct is defined like this :

class CONTEXT(Structure):
fields = [

    ("ContextFlags", DWORD),
    ("Dr0", DWORD),
    ("Dr1", DWORD),
    ("Dr2", DWORD),
    ("Dr3", DWORD),
    ("Dr6", DWORD),
    ("Dr7", DWORD),
    ("FloatSave", FLOATING_SAVE_AREA),
    ("SegGs", DWORD),
    ("SegFs", DWORD),
    ("SegEs", DWORD),
    ("SegDs", DWORD),
    ("Edi", DWORD),
    ("Esi", DWORD),
    ("Ebx", DWORD),
    ("Edx", DWORD),
    ("Ecx", DWORD),
    ("Eax", DWORD),
    ("Ebp", DWORD),
    ("Eip", DWORD),
    ("SegCs", DWORD),
    ("EFlags", DWORD),
    ("Esp", DWORD),
    ("SegSs", DWORD),
    ("ExtendedRegisters", BYTE * 512),

]

Sure, context.Dr6 is supposed to be a register, but it isn’t. It
doesn’t exist, because context is a bool, True or False, and bools don’t
have a Dr6 attribute.

I could answer your question in a literally correct, but
totally unhelpful manner, by saying

“Just assign the correct context object to self.context.”

which is literally correct but unhelpful because you probably don’t know
the correct context object or where to get it.

And neither do we.

You are asking us to solve a problem we know nothing about with
virtually no information.

What’s a CONTEXT struct in Windows C++? We’re Python programmers, and
being expert Windows C++ users is not a requirement for using Python.

Some of us don’t even use Windows.

Where does self.context come from? Did you write it yourself? Then you
have a bug in your code, and we can’t fix it because we don’t know what
you did wrong. Does it come from a library? Then maybe there is a bug in
the library, or maybe you are using it wrong, since you haven’t told us
the library, we can’t tell which.

My guess is that you are using something from Python 2.7, maybe even
older, because your code includes

self.breakpoints.has_key

which looks like it might be a dict. But dicts haven’t had a has_key
method since version 2.7, and even then it was obsolete. Using the
has_key method on dicts has not been ideomatic since version 1.5, around
a quarter of a century ago.

So it might help if you told us the version of Python you are running
too. I guess that you are probably on Windows.

, to version 1.5

Hey ,thank you very much for your fast answer.
I absolutely understand your point of view.

The problem showed to be a typo in some code dependent on the context object.
I have solved that and now the program runs smoothely.

Thanks again for your time and effort,

kind regards ,

Denis.