银河麒麟服务器系统中mysql数据库使用gdb内存回收报错问题处理

银河麒麟服务器系统中mysql数据库使用gdb内存回收报错问题处理

    • [一 系统环境](#一 系统环境)
    • [二 问题现象](#二 问题现象)
    • [三 分析原因](#三 分析原因)
    • [四 解决方法](#四 解决方法)

问题描述:在系统中执行回收命令(gdb --batch --pid pidof mysqld --ex 'call malloc_trim(0)';)报错'malloc_trim' has unknown return type; cast the call to its declared return type

一 系统环境

bash 复制代码
[root@localhost ~]# nkvers 
############## Kylin Linux Version #################
Release:
Kylin Linux Advanced Server release V10 (Sword)

Kernel:
4.19.90-24.4.v2101.ky10.x86_64

Build:
Kylin Linux Advanced Server
release V10 (SP2) /(Sword)-x86_64-Build09/20210524
#################################################

二 问题现象

bash 复制代码
[root@localhost ~]# gdb --batch --pid `pidof mysqld` --ex 'call malloc_trim(0)';
[New LWP 2916]
[New LWP 2917]
[New LWP 2918]
[New LWP 2919]
[New LWP 2920]
[New LWP 2921]
[New LWP 2922]
[New LWP 2923]
[New LWP 2924]
[New LWP 2925]
[New LWP 2926]
[New LWP 2927]
[New LWP 2929]
[New LWP 2930]
[New LWP 2931]
[New LWP 2932]
[New LWP 2933]
[New LWP 2934]
[New LWP 2935]
[New LWP 2936]
[New LWP 2937]
[New LWP 2938]
[New LWP 2939]
[New LWP 2940]
[New LWP 2941]
[New LWP 2942]
[New LWP 2943]
[New LWP 2944]
[New LWP 2945]

warning: Expected absolute pathname for libpthread in the inferior, but got target:/usr/lib64/libpthread.so.0.

warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.

warning: Expected absolute pathname for libpthread in the inferior, but got target:/usr/lib64/libpthread.so.0.

warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
0x00007fb2130629d9 in poll () from target:/usr/lib64/libc.so.6
'malloc_trim' has unknown return type; cast the call to its declared return type
[Inferior 1 (process 2914) detached]

三 分析原因

在C语言中,malloc_trim函数通常没有返回值,也就是说,它的返回类型是void。因此,malloc_trim函数不应该被强制转换为int类型。这样的转换在标准C语言中是没有意义的,因为malloc_trim不会返回一个整数值。

然而,一些特定的C库实现(如GNU C库)可能会为malloc_trim提供一个非标准的返回值,例如返回释放的内存字节数。在这种情况下,将malloc_trim的返回值强制转换为int可能是为了与这些非标准实现兼容。

总的来说,call (int)malloc_trim(0)call malloc_trim(0)在标准C语言中的行为应该是相同的,因为malloc_trim的标准定义不包含返回值。但是,如果您的代码依赖于某个特定C库的非标准扩展,那么这两种调用方式可能会有所不同:

  • call (int)malloc_trim(0):这种调用方式尝试将malloc_trim的任何返回值(如果有)强制转换为int类型。如果malloc_trim实际上返回了一个整数值,那么这个值将被转换为int类型。
  • call malloc_trim(0):这种调用方式忽略了malloc_trim的任何返回值。这是标准C语言中推荐的调用方式,因为它遵循了malloc_trim的标准定义。

需要将malloc_trim函数指定为int整数类型

四 解决方法

将gdb --batch --pid pidof mysqld --ex 'call malloc_trim(0)';命令修改为gdb --batch --pid pidof mysqld --ex 'call (int)malloc_trim(0)';

bash 复制代码
[root@localhost ~]# gdb --batch --pid `pidof mysqld` --ex 'call (int)malloc_trim(0)';
[New LWP 2916]
[New LWP 2917]
[New LWP 2918]
[New LWP 2919]
[New LWP 2920]
[New LWP 2921]
[New LWP 2922]
[New LWP 2923]
[New LWP 2924]
[New LWP 2925]
[New LWP 2926]
[New LWP 2927]
[New LWP 2929]
[New LWP 2930]
[New LWP 2931]
[New LWP 2932]
[New LWP 2933]
[New LWP 2934]
[New LWP 2935]
[New LWP 2936]
[New LWP 2937]
[New LWP 2938]
[New LWP 2939]
[New LWP 2940]
[New LWP 2941]
[New LWP 2942]
[New LWP 2943]
[New LWP 2944]
[New LWP 2945]

warning: Expected absolute pathname for libpthread in the inferior, but got target:/usr/lib64/libpthread.so.0.

warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.

warning: Expected absolute pathname for libpthread in the inferior, but got target:/usr/lib64/libpthread.so.0.

warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
0x00007fb2130629d9 in poll () from target:/usr/lib64/libc.so.6
$1 = 1
[Inferior 1 (process 2914) detached]
相关推荐
用户8055336980311 小时前
主线 U-Boot 上 RK3506:和闭源 rkbin 拔河的三个隐性契约
linux·嵌入式
用户0340952979111 小时前
linux fcitx 5 雾凇拼音 设置在中文输入法下仍然输入英文标点
linux
乘云数字DATABUFF12 小时前
5分钟部署开源APM Databuff:OpenTelemetry全链路追踪入门实战
运维·后端
SamDeepThinking12 小时前
一条UPDATE语句在MySQL 8.0中到底加了几把锁?
后端·mysql·程序员
Databend1 天前
在 AWS 中国峰会逛了一天,我在 Databend 展台看到了 Agent 数据基础设施的新思路
数据库·人工智能·agent
Web3探索者2 天前
可视化服务器管理和传统命令行区别是什么?新手教程:Linux 运维到底该用图形界面还是 SSH 命令行?
linux·ssh
李白客2 天前
KES新版MySQL兼容能力再升级意味着什么?
mysql·国产数据库
zylyehuo2 天前
Linux系统中网线与USB网络共享冲突
linux
ClouGence2 天前
Oracle 数据同步为什么会出现数据不一致?长事务是常被忽略的原因
数据库·后端·oracle
荣--2 天前
一键部署不是为了省时间 —— 它是把"买来的 PaaS"变成"自己的平台"的拐点
运维·zabbix·工程化·一键部署·平台化·边界设计