Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add DEBUGASSERT_MM_FREE_NODE macro #5968

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ewoodev
Copy link
Contributor

@ewoodev ewoodev commented Oct 23, 2023

commit 1

mm/mm_heap: add mm_dump_heap_free_node_list function

add mm_dump_heap_free_node_list function.
This function prints the hex valuse contents of heap free nodes using heap free node list.

example logs:

` #########################################################################################
  Dump heap free node list
  [ndx], [HEAD]: [FREE NODES(SIZE)]
` #########################################################################################
    0, 1003dc80:
    1, 1003dc98:
    2, 1003dcb0:
    3, 1003dcc8: 0200f220(240)
    4, 1003dce0:
    5, 1003dcf8: 02012dc0(592) 02016b70(576)
    6, 1003dd10: 0201eb70(1488)
    7, 1003dd28:
    8, 1003dd40:
    9, 1003dd58:
   10, 1003dd70:
   11, 1003dd88:
   12, 1003dda0:
   13, 1003ddb8:
   14, 1003ddd0:
   15, 1003dde8:
   16, 1003de00: 02201a10(1828320)
   17, 1003de18:
   18, 1003de30:
`  #########################################################################################

commit 2

mm/mm_heap: move dump_node to mm_dump_node

add the dump_node function, which was static, to the header for use in other codes and move it to mm_heap_dbg.c

commit 3

mm/mm_heap/mm_node.h: add DEBUGASSERT_MM_FREE_NODE macro

The back link of heap free node cannot be null at any time, If null, it is an assert situation.
Therefore, in the REMOVE_NODE_FROM_LIST macro, null is checked with DEBUGASSERT.
But we can't known why the back link of the free node became null.

Therefore, This commit adds DEBUGASSERT_MM_FREE_NODE macro, that print addresses of free nodes, head
list of free node link and corrupted node nearby node for debugging.

add mm_dump_heap_free_node_list function.
This function prints the hex valuse contents of heap free nodes using heap free node list.

example logs:

` #########################################################################################
  Dump heap free node list
  [ndx], [HEAD]: [FREE NODES(SIZE)]
` #########################################################################################
    0, 1003dc80:
    1, 1003dc98:
    2, 1003dcb0:
    3, 1003dcc8: 0200f220(240)
    4, 1003dce0:
    5, 1003dcf8: 02012dc0(592) 02016b70(576)
    6, 1003dd10: 0201eb70(1488)
    7, 1003dd28:
    8, 1003dd40:
    9, 1003dd58:
   10, 1003dd70:
   11, 1003dd88:
   12, 1003dda0:
   13, 1003ddb8:
   14, 1003ddd0:
   15, 1003dde8:
   16, 1003de00: 02201a10(1828320)
   17, 1003de18:
   18, 1003de30:
`  #########################################################################################

Signed-off-by: eunwoo.nam <eunwoo.nam@samsung.com>
add the dump_node function, which was static, to the header for use in other codes and move it to mm_heap_dbg.c.

Signed-off-by: eunwoo.nam <eunwoo.nam@samsung.com>
The back link of heap free node cannot be null at any time, If null, it is an assert situation.
Therefore, in the REMOVE_NODE_FROM_LIST macro, null is checked with DEBUGASSERT.
But we can't known why the back link of the free node became null.

Therefore, This commit adds DEBUGASSERT_MM_FREE_NODE macro, that print addresses of free nodes, head
list of free node link and corrupted node nearby node for debugging.

Signed-off-by: eunwoo.nam <eunwoo.nam@samsung.com>
@ewoodev ewoodev changed the title add DEBUGASSERT_MM_FREE_NODE macro [donotmerge]add DEBUGASSERT_MM_FREE_NODE macro Oct 23, 2023
@ewoodev ewoodev changed the title [donotmerge]add DEBUGASSERT_MM_FREE_NODE macro add DEBUGASSERT_MM_FREE_NODE macro Oct 26, 2023
do { \
DEBUGASSERT(node); \
if (!((node)->blink)) { \
abort_mode = true; \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DEBUGPANIC() is a macro for up_assert function and up_assert sets abort_mode to true internally. Is it necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
#define mfdbg(format, ...)						\
	do {								\
		if (!IS_SECURE_STATE()) {				\
			if (abort_mode || up_interrupt_context()) {	\
				lldbg(format, ##__VA_ARGS__);		\
			} else {					\
				dbg(format, ##__VA_ARGS__);		\
			}						\
		}							\
	} while (0)
#else
#define mfdbg(format, ...) dbg(format, ##__VA_ARGS__)
#endif

#define mfdbg(format, ...) \

mfdbg operation has dependency with abort_mode.

if after print mfdbg( using dbg), up_assert is called, dbg can't finsh printing.
becase uart driver and lib stdout buffer is stop and print only using lldbg.

So, To complete print just before up_assert, abort mode setting is needed.

Copy link
Contributor Author

@ewoodev ewoodev Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact.., This issue is not solved by setting abort_mode early about loadable user heap.. .
So, I'm checking to add lib stdout flush at up_assert.c


/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
#define DEBUGASSERT_MM_FREE_NODE(heap, node) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any reasons to separate DEBUGASSERT_MM_NODE according to build type? I think both are same except setting of abort_mode. If it is not necessary as I said in below comment, we don't need to separate them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants