How to make bpy.app.debug a prop? To show mesh indices you need to go to the Python console, type in bpy.app.debug, and then in the Mesh Display panel in Edit mode you can find the Show Extra Indices checkbox.

I would like to have a button or a checkbox in the Edit mode panel that sets the bpy.app.debug flag to true, so that i don't need to go to the python console for that.

The flag exists. So all it needs should be a prop with the valid parameters. That's where i struggle. It doesn't allow bpy.app, and when i just type in app then i get a warning that 'Context' object has no attribute 'app'

layout.prop(app, "debug", text="Debug")


How can i add a prop here that accesses bpy.app.debug?
Dummy property to update bpy.app.debug via UI



Script below uses a dummy boolean property on the window manager, with an update method to set bpy.app.debug to same.  Button is prepended to the 3D view header.

import bpy
from bpy.props import BoolProperty

def toggle_debug(self, context):
    bpy.app.debug = self.toggle_debug
    print("bpy.app.debug = ", self.toggle_debug)
    return None

bpy.types.WindowManager.toggle_debug = \
        BoolProperty(update=toggle_debug)

# function display the button
def display_toggle(self, context):
    layout = self.layout
    wm = context.window_manager
    layout.prop(wm, "toggle_debug", text="DEBUG", toggle=True)

# prepend to 3d view header
bpy.types.VIEW3D_HT_header.prepend(display_toggle)


To add properties to, or display properties in the UI,  the object must be an ID type.  Below is a simple test in python console to see if an object is an instance of an ID type.

&gt;&gt;&gt; isinstance(C.window_manager, bpy.types.ID)
True

&gt;&gt;&gt; isinstance(bpy.app, bpy.types.ID)
False


see that bpy.app is not, hence the error trying to use layout.prop(bpy.app, "debug")  

Also the error in your posted image is because app was not defined, assumed you meant bpy.app.